필터 지우기
필터 지우기

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 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