MATLAB ODEs using ode45

1 view (last 30 days)
tshuk18
tshuk18 on 22 Jan 2015
Answered: Torsten on 22 Jan 2015
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,'+');

Answers (1)

Torsten
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.

Community Treasure Hunt

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

Start Hunting!