Error while solving nonlinear differential equations using ode45
조회 수: 9 (최근 30일)
이전 댓글 표시
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.
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
댓글 수: 2
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?
채택된 답변
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
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
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
