Info

This question is closed. Reopen it to edit or answer.

How can I get fixed output in ode45

1 view (last 30 days)
Hüseyin Cagdas Yatkin
Hüseyin Cagdas Yatkin on 14 Dec 2019
Closed: MATLAB Answer Bot on 20 Aug 2021
I only get 20 output with this code. How can I get fixed output?
clc
clear
Cmeasured = [0 101 160 239 645 766 766 827 1122 1158 1591 2181 2566 2654 2944 3163 3406 3751 3982 3982 4425 4621 4746 4809 5240 5479 5604 5761 5885 5885 515418 515511 515511 516128 516203 516203 516252 516554 516991 517579 517969 518040 518040 518315 518566 518818 519166 519426 519426 519864 519969 520125 520125 520275 520441 520584 520723 520793 520793 536458 536540 536540 1562585 1562585 1562861 1561528 1561753 1562065 1562947 1562947
];
tspan = 0:1:1562947;
sol = ode45(@mt ,tspan ,[8.850 2] );
plot(sol.x',sol.y')
cagdas = sol.y';
function y = mt(t, C)
Cin = 1.800;
Kd = 0.00125/(24*60); %1/min
KL = 0.29/(24*60); %m/day
kl = 0.29/(24*60); %1/min
hw = 74.75; %depth of lake m
A = 18500*10^6; %Area m^2
L = 311*10^3; %Length m
Qin = 6400*60; %Inflow(niagara) m^3/min
Qout = 6700*60; %Outflow m^3/min
hs = 0.07; %depth of sediment that have DCB concentration m
Vw = hw*A; %Volume of water body m^3
Vs = hs*A*10^6; %Volume of sediment m^3
wt = 106/(365*24*60);
y(1) = ( Qin*Cin -(Qout)*C(1)- KL*A*C(1)-Kd*Vw*C(1)-kl*A*C(1))/Vw;
y(2) = (KL*A*C(1)-KL*A*C(2) - Kd*Vs*C(2))/Vs;
y=y(:);
end

Answers (1)

Cris LaPierre
Cris LaPierre on 18 Mar 2020
Use the following calling syntax instead. This results in a value in y corresponding to each time point specified in tspan.
tspan = 0:1:1562947;
[t,y] = ode45(@mt ,tspan ,[8.850 2] );
plot(t,y(:,1),t,y(:,2))

This question is closed.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!