Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
Aaron
Aaron el 11 de Sept. de 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?

Respuesta aceptada

Jan
Jan el 11 de Sept. de 2013
Editada: Jan el 11 de Sept. de 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

Más respuestas (0)

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by