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

1 次查看(过去 30 天)
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?

采纳的回答

Jan
Jan 2013-9-11
编辑:Jan 2013-9-11
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by