System of ODE: derivative inside equation

1 次查看(过去 30 天)
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 个评论
Torsten
Torsten 2017-2-24
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.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by