Error while solving nonlinear differential equations using ode45

조회 수: 9 (최근 30일)
BISMARK
BISMARK 2021년 5월 4일
댓글: BISMARK 2021년 5월 4일
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
Alan Stevens
Alan Stevens 2021년 5월 4일
편집: Alan Stevens 2021년 5월 4일
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?
BISMARK
BISMARK 2021년 5월 4일
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

댓글을 달려면 로그인하십시오.

채택된 답변

Alan Stevens
Alan Stevens 2021년 5월 4일
Then this line
[t,y0]=ode45(@evapmodel,tspan,y0);
should presumably be
[t,y0]=ode45(@evapfunc,tspan,y0);
  댓글 수: 3
Alan Stevens
Alan Stevens 2021년 5월 4일
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
BISMARK
BISMARK 2021년 5월 4일
Thanks so much. This worked.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by