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

1 回表示 (過去 30 日間)
Aaron
Aaron 2013 年 9 月 11 日
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 Center および File ExchangeOrdinary Differential Equations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by