Example in your ode45 tutorial is not running
1 view (last 30 days)
Show older comments
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?
0 Comments
Answers (2)
Nasir Qazi
on 8 Apr 2012
[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) .
0 Comments
Walter Roberson
on 10 Aug 2011
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.
0 Comments
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!