MATLAB ODEs using ode45
Afficher commentaires plus anciens
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,'+');
Réponses (1)
Torsten
le 22 Jan 2015
0 votes
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.
Catégories
En savoir plus sur Ordinary Differential Equations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!