Error while solving nonlinear differential equations using ode45

clear
%parameters are defined
global F1 F2 T1 X1 M C P100 F200 T200 F3
F2=2.0;P100=194.7;F200=208.0;F1=10.0,T1=40.0;X1=5.0;F3=50.0;T200=25.0; M=20.0;C=4.0;
tspan=[0 600] %simulation time
y0=[1.0 25.0 50.5] %arbitrary initial conditions
t=tspan
[t,y0]=ode45(@evapmodel,tspan,y0);
%figures
figure(1),clf
plot(t,y(:,1),t,y(:,2),t,y(:,3),'--')
legend('L2','X2','P2')
xlabel('t')
ylabel('Output Parameters')
Here is the ERROR :(
Unrecognized function or variable 'evapmodel'.
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);

2 commentaires

Alan Stevens
Alan Stevens le 4 Mai 2021
Modifié(e) : Alan Stevens le 4 Mai 2021
What does your evapmodel function look like, and have you saved it in a separate file, or at the end of the file you've shown? Are you running it from the workspace or the file?
The evapmodel is the above code and the evapfunc looks like this. I have saved it in the same file and run it on a separate live editor.
function dydt = evapfunc(t,y)
%evapfunc summary of this function goes here
global F1 F2 T1 X1 M C P100 F200 T200 F3
%calculate other variables
T2 = 0.5616*y(3)+0.3126*y(2)+48.43;
T3 = 0.507*y(3)+55.0;
T100=0.1538*P100+90.0;
Q100=0.16*(F1+F3)*(T100-T2);
F4= Q100-F1*0.07*38.5*(T2-T1)/38.5;
F100=Q100/36.6;
Q200=6.84*(T3-T200)/1+(6.84/0.07*F200);
T201=T200+Q200/F200*0.07;
F5=Q200/38.5;
%Calculation of outputs
dL2dt= F1-F2-F4/20;
dX2dt=F1*X1-F2*y(2)/M;
dP2dt=F4-F5/C;
dydt=[dL2dt;dX2dt;dP2dt];
end

Connectez-vous pour commenter.

 Réponse acceptée

Then this line
[t,y0]=ode45(@evapmodel,tspan,y0);
should presumably be
[t,y0]=ode45(@evapfunc,tspan,y0);

3 commentaires

I am still getting this same error. I am not sure what i am doing wrong.
Unrecognized function or variable 'evapfunc'.
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
The following works:
global F1 F2 T1 X1 M C P100 F200 T200 F3
F2=2.0;P100=194.7;F200=208.0;F1=10.0;T1=40.0;X1=5.0;F3=50.0;T200=25.0; M=20.0;C=4.0;
tspan=[0 600]; %simulation time
y0=[1.0 25.0 50.5]; %arbitrary initial conditions
t=tspan;
[t,y]=ode45(@evapfunc,tspan,y0);
%figures
figure(1),clf
plot(t,y(:,1),t,y(:,2),t,y(:,3),'--')
legend('L2','X2','P2')
xlabel('t')
ylabel('Output Parameters')
function dydt = evapfunc(~,y)
%evapfunc summary of this function goes here
global F1 F2 T1 X1 M C P100 F200 T200 F3
%calculate other variables
T2 = 0.5616*y(3)+0.3126*y(2)+48.43;
T3 = 0.507*y(3)+55.0;
T100=0.1538*P100+90.0;
Q100=0.16*(F1+F3)*(T100-T2);
F4= Q100-F1*0.07*38.5*(T2-T1)/38.5;
F100=Q100/36.6;
Q200=6.84*(T3-T200)/1+(6.84/0.07*F200);
T201=T200+Q200/F200*0.07;
F5=Q200/38.5;
%Calculation of outputs
dL2dt= F1-F2-F4/20;
dX2dt=F1*X1-F2*y(2)/M;
dP2dt=F4-F5/C;
dydt=[dL2dt;dX2dt;dP2dt];
end
Thanks so much. This worked.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Centre d'aide et File Exchange

Produits

Version

R2020b

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by