System of ODE: derivative inside equation

1 Ansicht (letzte 30 Tage)
Marco Sammito
Marco Sammito am 24 Feb. 2017
Kommentiert: Torsten am 24 Feb. 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 Kommentar
Torsten
Torsten am 24 Feb. 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.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by