System of ODE: derivative inside equation
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Torsten
le 24 Fév 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.
Réponses (0)
Voir également
Catégories
En savoir plus sur Ordinary Differential Equations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!