Borrar filtros
Borrar filtros

Example in your ode45 tutorial is not running

1 visualización (últimos 30 días)
Nana
Nana el 10 de Ag. de 2011
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?

Respuestas (2)

Nasir Qazi
Nasir Qazi el 8 de Abr. de 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) .

Walter Roberson
Walter Roberson el 10 de Ag. de 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.

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by