ODE45 solving for three variables

60 Ansichten (letzte 30 Tage)
Valeria Moreno
Valeria Moreno am 23 Okt. 2020
Bearbeitet: Ameer Hamza am 23 Okt. 2020
Hello
I am trying to solve for an ODE with
y1'=y2
y2'=y3
y3'=-24y1-26y2-9y3
y(0)=[1 -4 -14]
when I try to code it like this
dydt = [y(2); y(3); -24*y(1)-26*y(2)-9*y(3)];
an error appears
Index exceeds the number of array elements (1).
R_tilde = builtin('subsref',L_tilde,Idx);
I'm pretty new to this so sorry if this is a simple question

Antworten (1)

Ameer Hamza
Ameer Hamza am 23 Okt. 2020
Bearbeitet: Ameer Hamza am 23 Okt. 2020
You need to write as a function or a function handle
dydt = @(t, y) [y(2); y(3); -24*y(1)-26*y(2)-9*y(3)];
y0 = [1 -4 -14];
tspan = [0 10];
[t, y] = ode45(dydt, tspan, y0);
plot(t, y);

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by