MATLAB ODEs using ode45
1 view (last 30 days)
Show older comments
Hello everyone. I am trying to solve 3 ODEs, so I have put them in 3 different function files. I am trying to call them in my script file, but I am always getting major errors. Can someone help me out please?
equationA.m
function dy1 = equationA(y1)
k1 = 0.0005;
dy1 = -k1*y1;
end
equationB.m
function [dy01,dy2,dy] = equationB(y1,y2)
dy01 = 0.0005*y1;
dy2 = - 0.0002*y2;
dy = dy01 + dy2; end
equationC.m
function dy3 = equationC(y3)
k2=0.0001;
dy3 = k2*y2;
end
ode.m (script file)
[T1,Y1] = ode45(@equationA,[0,10],0.0005);
[T2,Y2] = ode45(@equationB,[0,10],0);
[T3,Y3] = ode45(@equationC,[0,10],0.0001);
plot(T1,Y1,'*');
hold on
plot(T2,Y2,'-');
hold on
plot(T3,Y3,'+');
0 Comments
Answers (1)
Torsten
on 22 Jan 2015
The ODE function file must be of the form
dydt = myfun(t,y)
In all three cases above, your function file differs from this prescribed form.
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!