Ode45 solver error messages, how do I fix my script?
6 views (last 30 days)
Show older comments
Hi, I ran the script below but I got some error messages which I didn't understand. Can someone help me with what the messages mean and point me on how to solve? I can see the problem is to do with PL when it is passed on to the function. Please help.
Error using odearguments (line 92) @(T,X)[(1./X(2)).*(PM.*(PM-X(1)./R))-X(1).*X(3);X(3);(1./IA).*(X(1)-PL-RA.*X(3)-E.*(X(2)-VO))] returns a vector of length 71, but the length of initial conditions vector is 3. The vector returned by @(T,X)[(1./X(2)).*(PM.*(PM-X(1)./R))-X(1).*X(3);X(3);(1./IA).*(X(1)-PL-RA.*X(3)-E.*(X(2)-VO))] and the initial conditions vector must have the same number of elements.
Error in ode45 (line 113) [neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
Error in Flexible_Lung (line 18) [t,xa] = ode45(f,[0 1.5],[760 2.295 -0.12949]);
Pm = 760;
R = 1;
vol_tid = 0.41;
Ra = 0;
w = 2*pi*0.2;
E = 2.8;
Vo = 01;
Ia = 0.0074;
PL = Pm -(R*w).*(0.5*vol_tid).*sin(w.*t) - E*((2.5 - (0.5 * vol_tid)) * cos(w.*t));
f = @(t,x) [ (1./x(2)).*(Pm.*(Pm-x(1)./R)) - x(1).*x(3) ; x(3) ; (1./Ia).*(x(1)-PL - Ra.*x(3) - E.*(x(2)-Vo))];
[t,xa] = ode45(f,[0 1.5],[760 2.295 -0.12949]);
n=Pm-PL
plot(n,xa(:,2))
0 Comments
Answers (1)
Torsten
on 11 Mar 2015
Try
f = @(t,x) [ (1./x(2)).*(Pm.*(Pm-x(1)./R)) - x(1).*x(3) ; x(3) ; (1./Ia).*(x(1)-(Pm -(R*w).*(0.5*vol_tid).*sin(w.*t) - E*((2.5 - (0.5 * vol_tid)) * cos(w.*t))) - Ra.*x(3) - E.*(x(2)-Vo))];
Best wishes
Torsten.
0 Comments
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!