필터 지우기
필터 지우기

Example in your ode45 tutorial is not running

조회 수: 1 (최근 30일)
Nana
Nana 2011년 8월 10일
I have the same problem trying to solve 3 nonlinear differential equations for my modeling.
I tried to run your own tutorial example:
function dy = rigid(t,y)
dy = zeros(3,1); % a column vector
dy(1) = y(2) * y(3);
dy(2) = -y(1) * y(3);
dy(3) = -0.51 * y(1) * y(2);
options = odeset('RelTol',1e-4,'AbsTol',[1e-4 1e-4 1e-5]);
[T,Y] = ode45(@rigid,[0 12],[0 1 1],options);
plot(T,Y(:,1),'-',T,Y(:,2),'-.',T,Y(:,3),'.')
and the following error message came up
??? Input argument "y" is undefined.
Error in ==> rigid at 3
dy(1) = y(2) * y(3);
what do you think is the best way to deal with the problem?

답변 (2개)

Nasir Qazi
Nasir Qazi 2012년 4월 8일
[T,Y] = ode45(@rigid,[0 12],[0 1 1],options);
where the [0 1 1] , should be in [0 1 1]' , so you can assign the values to y(1),y(2) and y(3) .

Walter Roberson
Walter Roberson 2011년 8월 10일
You need to separate that in to two parts. The first 5 lines need to go in to a file named rigid.m and the options through plot line go in to a second file. You would run the second file to do the fitting.
With the way you have the code now, if you did manage to get past the error about y not being defined, then you would end up invoking rigid in an infinite loop, since your ode45 call within your function named "rigid" is requesting that "rigid" be invoked... which would invoke ode45 again, which would invoke rigid again, and so on.

카테고리

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