How to solve Coupled Differential Equations

135 ビュー (過去 30 日間)
Tomasz
Tomasz 2021 年 5 月 9 日
コメント済み: Walter Roberson 2021 年 5 月 9 日
Hi
how to solve that set of equations
y'-x'=2-x
2x'-y'=3+2y

回答 (2 件)

Star Strider
Star Strider 2021 年 5 月 9 日
Try this —
syms x(t) y(t) x0 y0
Dx = diff(x);
Dy = diff(y);
ode1 = Dy-Dx == 2 - x
ode1(t) = 
ode2 = 2-Dy - Dy == 3 + 2*y
ode2(t) = 
S = dsolve(ode1, ode2, x(0)==x0, y(0)==y0)
S = struct with fields:
y: [1×1 sym] x: [1×1 sym]
x(t) = simplify(S.x, 500)
x(t) = 
y(t) = simplify(S.y, 500)
y(t) = 
.

Walter Roberson
Walter Roberson 2021 年 5 月 9 日
yprime - xprime == 2-x, 2*xprime - yprime == 3 + 2*y
2*yprime - 2*xprime == 4-2*x, 2*xprime - yprime == 3 + 2*y
2*yprime - 2*xprime + 2*xprime - yprime == 4-2*x + 3 + 2*y
yprime == 7 - 2*x + 2*y
7 - 2*x + 2*y - xprime == 2*x
7 - 2*x + 2*y - 2*x == xprime
xprime = 7 - 4*x + 2*y
So...
function dxy = odefun(t, xy)
dxy = [7 - 4*xy(1) + 2*xy(2); 7 - 2*xy(1) + 2*xy(2)];
end
  4 件のコメント
Walter Roberson
Walter Roberson 2021 年 5 月 9 日
syms xprime yprime x y
eqn = [yprime - xprime == 2-x, 2*xprime - yprime == 3 + 2*y]
eqn = 
sol = solve(eqn, [xprime, yprime])
sol = struct with fields:
xprime: [1×1 sym] yprime: [1×1 sym]
sol.xprime
ans = 
sol.yprime
ans = 
Hmmm, where did I go wrong?
Walter Roberson
Walter Roberson 2021 年 5 月 9 日
I did make a mistake, but it was the step after you indicated. I copied as 2*x instead of 2-x . The corrected version is
yprime - xprime == 2-x, 2*xprime - yprime == 3 + 2*y
2*yprime - 2*xprime == 4-2*x, 2*xprime - yprime == 3 + 2*y
2*yprime - 2*xprime + 2*xprime - yprime == 4-2*x + 3 + 2*y
yprime == 7 - 2*x + 2*y
7 - 2*x + 2*y - xprime == 2 - x %corrected
7 - 2*x + 2*y - (2 - x) == xprime
xprime = 5 - x + 2*y
So...
function dxy = odefun(t, xy)
dxy = [5 - xy(1) + 2*xy(2); 7 - 2*xy(1) + 2*xy(2)];
end

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by