MATLAB ODEs using ode45

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,'+');

回答(1 个)

Torsten
Torsten 2015-1-22

0 个投票

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.

类别

提问:

2015-1-22

回答:

2015-1-22

Community Treasure Hunt

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

Start Hunting!

Translated by