ode45 coupled first degree ODEs

1 visualización (últimos 30 días)
Serhat Unal
Serhat Unal el 17 de Sept. de 2020
Comentada: Serhat Unal el 17 de Sept. de 2020
I want to solve two coupled ODEs in matlab using ODE45, but get an error that says U"nable to perform assignment because the left and right sides have a different number of elements". I dont know really what the problem is here and have tried severad changes but did not fix it.
Code:
function dz = myode(v,z)
a = 0.4;
b = 0.001;
c = 0.001;
d = 0.9;
dz = zeros(2,1);
dz(1) = a*z(1)-b*z(2)*z(1);
dz(2) = c*z(1)*z(2)-diff(z(2));
end
I call it as:
[v z] = ode45(@myode,[0 40],[2 6])
Hope someone can help
  1 comentario
esat gulhan
esat gulhan el 17 de Sept. de 2020
What is your differantial code. can you give your diff equation dz/dv....

Iniciar sesión para comentar.

Respuestas (1)

Alan Stevens
Alan Stevens el 17 de Sept. de 2020
Do you mean something like this:
[v, z] = ode45(@myode,[0 40],[2 6]);
plot(v,z)
function dz = myode(~,z)
a = 0.4;
b = 0.001;
c = 0.001;
d = 0.9;
dz = [a*z(1)-b*z(2)*z(1);
c*z(1)*z(2)-d*z(2)];
end
You had diff(z(2)), but d was unused, so I assumed you meant d*z(2). However, this might not have been what you wanted!
  1 comentario
Serhat Unal
Serhat Unal el 17 de Sept. de 2020
oh thank you I have just read it wrong and thought it was an derivative. Therefore It became very confusing but now it works, thanks!

Iniciar sesión para comentar.

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