Error when solving system of equations with ode45 in MATLAB R2019b

1 visualización (últimos 30 días)
Hi there,
I'm currently getting an error about the length of vectors that my function is returning when solving with ode45.
my system is as follows:
x' = -uxy
y' = u(xy-y(y-1)-yz)
I looked at several tutorials describing how to do this including one which used the same number of parameters which I adapted to my code. It does not seem to have caused any errors in those previous cases so I'm confused why I'm receiving this error.
My code and the error are as follows:
fun=@(t,y)[-y(1)*y(2)*y(3);y(1)*(y(2)*y(3)-y(3)*(y(3)-1)-y(3)*y(4))];
u= 0.75;
x= 75;
y= 1;
z= 0;
Y0=[u; x; y; z];
tspan=[0 2.5];
[T,Y]=ode45(fun,tspan,Y0);
plot(T,Y(:,1)) %plot x
plot(T,Y(:,3)) %plot y
Error using odearguments (line 95)
@(T,Y)[-Y(1)*Y(2)*Y(3);Y(1)*(Y(2)*Y(3)-Y(3)*(Y(3)-1)-Y(3)*Y(4))]
returns a vector of length 2, but the length of initial conditions vector is 4.
The vector returned by @(T,Y)[-Y(1)*Y(2)*Y(3);Y(1)*[Y(2)*Y(3)-Y(3)*(Y(3)-1)-Y(3)*Y(4)]]
and the initial conditions vector must have the same number of elements.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);

Respuesta aceptada

Star Strider
Star Strider el 21 de Feb. de 2020
The system contains only two derivatives, and . It appears that ‘u’ and ‘z’ are either functions that need to be evaluated, or constants that need to be passed as extra parameters. (I am not certain what they are.) If they are parameters, then the documentation section on Passing Extra Parameters would be important. If they are functions, we need more information about them.

Más respuestas (0)

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by