Example in your ode45 tutorial is not running

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