I'm not sure what else I'm missing?

1 Ansicht (letzte 30 Tage)
Aaron
Aaron am 11 Sep. 2013
I've been trying to solve an ODE using ode45 and here is my code:
function dydt = odepro4(t,y)
t = 0;
y = 1;
dydt = (y.*t).^3 - (1.5*y);
[t,y] = ode45(odepro4(t,y),[0,2],y);
end
Other information: y(0) = 1 t = 1
Our instructor just wrote some stuff on the board and told us we could use it for our homework. But I'm not sure if we are supposed to create one function file and then a script, or if this can be solved using one file?

Akzeptierte Antwort

Jan
Jan am 11 Sep. 2013
Bearbeitet: Jan am 11 Sep. 2013
This is a frequently asked question, to my surprise.
You have inserted the call to the integrator inside the function to be integrated. This starts an infinite recursion, because the integrator called the function to be integrated to get the values.
Better:
function myHomework
y = 1;
[t,y] = ode45(@odepro4, [0,2], y);
plot(t, y);
function dydt = odepro4(t,y)
dydt = (y.*t).^3 - (1.5*y);
end
This can be written to the M-file "myHomework.m".
Further explanations can be found, if you read the documentation:
doc ode45

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by