System of ODE: derivative inside equation

1 visualización (últimos 30 días)
Marco Sammito
Marco Sammito el 24 de Feb. de 2017
Comentada: Torsten el 24 de Feb. de 2017
Hi. I have to solve this system of ODE:
How should I treat x'_3 in the second equation? I tried two different approaches but I get different results:
function equazione()
[t,x] = ode45(@(t,x) F(t,x), [0, 3], [2, 1, 1]);
plot(t,x(:,1))
end
function xp = F(t,x)
xp = zeros(3,1);
xp(1) = x(2);
xp(2) = -t * x(1) - exp(t) * x(2) + 3 * cos(2 * t) + xp(3);% <- See this last term
xp(3) = exp(t);
end
and
function equazione()
[t,x] = ode45(@(t,x) F(t,x), [0, 3], [2, 1, 1]);
plot(t,x(:,1))
end
function xp = F(t,x)
xp = zeros(3,1);
xp(1) = x(2);
xp(2) = -t * x(1) - exp(t) * x(2) + 3 * cos(2 * t) + exp(t);% <- See this last term
xp(3) = exp(t);
end
Red line: 1st approach Blue line: 2nd approach
%
  1 comentario
Torsten
Torsten el 24 de Feb. de 2017
The second approach is the correct one.
In the first approach, you only add 0 to -t * x(1) - exp(t) * x(2) + 3 * cos(2 * t) because xp is preallocated as zeros(3,1). This is obvioulsy incorrect.
Best wishes
Torsten.

Iniciar sesión para comentar.

Respuestas (0)

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