solegs.mw

Solving Two Dimensional Systems of Linear Differential Equations. 

 

> restart; with(LinearAlgebra):
 

A utiity procedure. 

> buildsys := proc(mat)
{diff(x(t),t)=mat[1,1]*x(t)+mat[1,2]*y(t), diff(y(t),t)=mat[2,1]*x(t)+mat[2,2]*y(t)};
end;
 

Typesetting:-mprintslash([`:=`(buildsys, proc (mat) {diff(x(t), t) = `+`(`*`(mat[1, 1], `*`(x(t))), `*`(mat[1, 2], `*`(y(t)))), diff(y(t), t) = `+`(`*`(mat[2, 1], `*`(x(t))), `*`(mat[2, 2], `*`(y(t)))...
Typesetting:-mprintslash([`:=`(buildsys, proc (mat) {diff(x(t), t) = `+`(`*`(mat[1, 1], `*`(x(t))), `*`(mat[1, 2], `*`(y(t)))), diff(y(t), t) = `+`(`*`(mat[2, 1], `*`(x(t))), `*`(mat[2, 2], `*`(y(t)))...
Typesetting:-mprintslash([`:=`(buildsys, proc (mat) {diff(x(t), t) = `+`(`*`(mat[1, 1], `*`(x(t))), `*`(mat[1, 2], `*`(y(t)))), diff(y(t), t) = `+`(`*`(mat[2, 1], `*`(x(t))), `*`(mat[2, 2], `*`(y(t)))...
 

>
 

>
 

>
 

>
 

Diagonializable, real eigenvalues. 

 

> A := Matrix([[-4, 6], [-3, 5]]);
 

Typesetting:-mprintslash([`:=`(A, Matrix([[-4, 6], [-3, 5]]))], [Matrix(%id = 7707720)])
 

>
 

> sys := buildsys(A);
 

Typesetting:-mprintslash([`:=`(sys, {diff(x(t), t) = `+`(`-`(`*`(4, `*`(x(t)))), `*`(6, `*`(y(t)))), diff(y(t), t) = `+`(`-`(`*`(3, `*`(x(t)))), `*`(5, `*`(y(t))))})], [{diff(x(t), t) = `+`(`-`(`*`(4,...
 

Initial Condition  

> xno := <a,b>;
 

Typesetting:-mprintslash([`:=`(xno, Vector[column]([[a], [b]]))], [Vector[column](%id = 7643712)])
 

Maple's Solution 

> sol := dsolve(sys union {x(0)=a, y(0)=b}, [x(t),y(t)]);
 

Typesetting:-mprintslash([`:=`(sol, {x(t) = `+`(`*`(2, `*`(`+`(a, `-`(b)), `*`(exp(`+`(`-`(t)))))), `*`(`+`(`-`(a), `*`(2, `*`(b))), `*`(exp(`+`(`*`(2, `*`(t))))))), y(t) = `+`(`*`(`+`(a, `-`(b)), `*`...
 

Now, we'll solve it. 

>
 

> evv := Eigenvectors(A);
 

Typesetting:-mprintslash([`:=`(evv, Vector[column]([[-1], [2]]), Matrix([[2, 1], [1, 1]]))], [Vector[column](%id = 13846808), Matrix(%id = 7580592)])
 

> P:=evv[2];
 

Typesetting:-mprintslash([`:=`(P, Matrix([[2, 1], [1, 1]]))], [Matrix(%id = 7580592)])
 

> P^(-1).A.P;
 

Typesetting:-mprintslash([Matrix([[-1, 0], [0, 2]])], [Matrix(%id = 14272288)])
 

> zmat := DiagonalMatrix([exp(2*t), exp(-t)]);
 

Typesetting:-mprintslash([`:=`(zmat, Matrix([[exp(`+`(`*`(2, `*`(t)))), 0], [0, exp(`+`(`-`(t)))]]))], [Matrix(%id = 7676896)])
 

> xsol := P.zmat.P^(-1).xno;
 

Typesetting:-mprintslash([`:=`(xsol, Vector[column]([[`+`(`*`(`+`(`*`(2, `*`(exp(`+`(`*`(2, `*`(t)))))), `-`(exp(`+`(`-`(t))))), `*`(a)), `*`(`+`(`-`(`*`(2, `*`(exp(`+`(`*`(2, `*`(t))))))), `*`(2, `*`...
 

Rearrange to compare with Maple. 

>
 

> map(collect, %, [exp(2*t), exp(-t)]);
 

Typesetting:-mprintslash([Vector[column]([[`+`(`*`(`+`(`*`(2, `*`(a)), `-`(`*`(2, `*`(b)))), `*`(exp(`+`(`*`(2, `*`(t)))))), `*`(`+`(`-`(a), `*`(2, `*`(b))), `*`(exp(`+`(`-`(t))))))], [`+`(`*`(`+`(a, ...
 

>
 

>
 

Diagonalizable, nonreal eigenvalues. 

>
 

> A := Matrix([[11, -6], [15, -7]]);
 

Typesetting:-mprintslash([`:=`(A, Matrix([[11, -6], [15, -7]]))], [Matrix(%id = 9850104)])
 

>
 

>
 

> sys := buildsys(A);
 

Typesetting:-mprintslash([`:=`(sys, {diff(x(t), t) = `+`(`*`(11, `*`(x(t))), `-`(`*`(6, `*`(y(t))))), diff(y(t), t) = `+`(`*`(15, `*`(x(t))), `-`(`*`(7, `*`(y(t)))))})], [{diff(x(t), t) = `+`(`*`(11, ...
 

> dsol:=dsolve(sys union {x(0)=a, y(0)=b}, [x(t), y(t)]);
 

Typesetting:-mprintslash([`:=`(dsol, {y(t) = `*`(exp(`+`(`*`(2, `*`(t)))), `*`(`+`(`*`(`+`(`-`(`*`(3, `*`(b))), `*`(5, `*`(a))), `*`(sin(`+`(`*`(3, `*`(t)))))), `*`(b, `*`(cos(`+`(`*`(3, `*`(t))))))))...
Typesetting:-mprintslash([`:=`(dsol, {y(t) = `*`(exp(`+`(`*`(2, `*`(t)))), `*`(`+`(`*`(`+`(`-`(`*`(3, `*`(b))), `*`(5, `*`(a))), `*`(sin(`+`(`*`(3, `*`(t)))))), `*`(b, `*`(cos(`+`(`*`(3, `*`(t))))))))...
 

>
 

>
 

> evv := Eigenvectors(A);
 

Typesetting:-mprintslash([`:=`(evv, Vector[column]([[`+`(2, `*`(3, `*`(I)))], [`+`(2, `-`(`*`(3, `*`(I))))]]), Matrix([[`+`(`/`(3, 5), `*`(`/`(1, 5), `*`(I))), `+`(`/`(3, 5), `-`(`*`(`/`(1, 5), `*`(I)...
 

> P := evv[2];
 

Typesetting:-mprintslash([`:=`(P, Matrix([[`+`(`/`(3, 5), `*`(`/`(1, 5), `*`(I))), `+`(`/`(3, 5), `-`(`*`(`/`(1, 5), `*`(I))))], [1, 1]]))], [Matrix(%id = 13001928)])
 

> p1 := Column(P,1);
 

Typesetting:-mprintslash([`:=`(p1, Vector[column]([[`+`(`/`(3, 5), `*`(`/`(1, 5), `*`(I)))], [1]]))], [Vector[column](%id = 15347768)])
 

> u := map(Re,p1);
 

Typesetting:-mprintslash([`:=`(u, Vector[column]([[`/`(3, 5)], [1]]))], [Vector[column](%id = 15348272)])
 

> v := -map(Im, p1);
 

Typesetting:-mprintslash([`:=`(v, Vector[column]([[-`/`(1, 5)], [0]]))], [Vector[column](%id = 15348848)])
 

> u - I*v;
 

Typesetting:-mprintslash([Vector[column]([[`+`(`/`(3, 5), `*`(`/`(1, 5), `*`(I)))], [1]])], [Vector[column](%id = 15349784)])
 

> Q := <u|v>;
 

Typesetting:-mprintslash([`:=`(Q, Matrix([[`/`(3, 5), -`/`(1, 5)], [1, 0]]))], [Matrix(%id = 15970064)])
 

> B:=Q^(-1).A.Q;
 

Typesetting:-mprintslash([`:=`(B, Matrix([[2, -3], [3, 2]]))], [Matrix(%id = 16095520)])
 

> zmat := << exp(2*t)*cos(3*t)|-exp(2*t)*sin(3*t)>,
<exp(2*t)*sin(3*t)| exp(2*t)*cos(3*t)>>;
 

Typesetting:-mprintslash([`:=`(zmat, Matrix([[`*`(exp(`+`(`*`(2, `*`(t)))), `*`(cos(`+`(`*`(3, `*`(t)))))), `+`(`-`(`*`(exp(`+`(`*`(2, `*`(t)))), `*`(sin(`+`(`*`(3, `*`(t))))))))], [`*`(exp(`+`(`*`(2,...
 

> xsol := Q.zmat.Q^(-1).xno;
 

Typesetting:-mprintslash([`:=`(xsol, Vector[column]([[`+`(`*`(`+`(`*`(3, `*`(exp(`+`(`*`(2, `*`(t)))), `*`(sin(`+`(`*`(3, `*`(t))))))), `*`(exp(`+`(`*`(2, `*`(t)))), `*`(cos(`+`(`*`(3, `*`(t))))))), `...
 

To check that this is the same as Maple's solution, create differences 

> {x(t)-xsol[1], y(t)-xsol[2]};
 

{`+`(y(t), `-`(`*`(5, `*`(exp(`+`(`*`(2, `*`(t)))), `*`(sin(`+`(`*`(3, `*`(t)))), `*`(a))))), `-`(`*`(`+`(`*`(exp(`+`(`*`(2, `*`(t)))), `*`(cos(`+`(`*`(3, `*`(t)))))), `-`(`*`(3, `*`(exp(`+`(`*`(2, `*...
{`+`(y(t), `-`(`*`(5, `*`(exp(`+`(`*`(2, `*`(t)))), `*`(sin(`+`(`*`(3, `*`(t)))), `*`(a))))), `-`(`*`(`+`(`*`(exp(`+`(`*`(2, `*`(t)))), `*`(cos(`+`(`*`(3, `*`(t)))))), `-`(`*`(3, `*`(exp(`+`(`*`(2, `*...
 

Now substitute Maple's solutions for Typesetting:-mrow(Typesetting:-mi( and Typesetting:-mrow(Typesetting:-mi( 

> subs(dsol, %);
 

{`+`(`*`(exp(`+`(`*`(2, `*`(t)))), `*`(`+`(`*`(`+`(`-`(`*`(3, `*`(b))), `*`(5, `*`(a))), `*`(sin(`+`(`*`(3, `*`(t)))))), `*`(b, `*`(cos(`+`(`*`(3, `*`(t))))))))), `-`(`*`(5, `*`(exp(`+`(`*`(2, `*`(t))...
{`+`(`*`(exp(`+`(`*`(2, `*`(t)))), `*`(`+`(`*`(`+`(`-`(`*`(3, `*`(b))), `*`(5, `*`(a))), `*`(sin(`+`(`*`(3, `*`(t)))))), `*`(b, `*`(cos(`+`(`*`(3, `*`(t))))))))), `-`(`*`(5, `*`(exp(`+`(`*`(2, `*`(t))...
{`+`(`*`(exp(`+`(`*`(2, `*`(t)))), `*`(`+`(`*`(`+`(`-`(`*`(3, `*`(b))), `*`(5, `*`(a))), `*`(sin(`+`(`*`(3, `*`(t)))))), `*`(b, `*`(cos(`+`(`*`(3, `*`(t))))))))), `-`(`*`(5, `*`(exp(`+`(`*`(2, `*`(t))...
 

> map(simplify, %);
 

{0}
 

>
 

Nondiagonalizable. 

>
 

> A := Matrix([[-8/3, 4/3], [-1/3, -4/3]]);
 

Typesetting:-mprintslash([`:=`(A, Matrix([[-`/`(8, 3), `/`(4, 3)], [-`/`(1, 3), -`/`(4, 3)]]))], [Matrix(%id = 11628720)])
 

> sys := buildsys(A);
 

Typesetting:-mprintslash([`:=`(sys, {diff(x(t), t) = `+`(`-`(`*`(`/`(8, 3), `*`(x(t)))), `*`(`/`(4, 3), `*`(y(t)))), diff(y(t), t) = `+`(`-`(`*`(`/`(1, 3), `*`(x(t)))), `-`(`*`(`/`(4, 3), `*`(y(t)))))...
 

> dsol := dsolve(sys union {y(0)=b, x(0)=a}, [x(t), y(t)]);
 

Typesetting:-mprintslash([`:=`(dsol, {y(t) = `*`(exp(`+`(`-`(`*`(2, `*`(t))))), `*`(`+`(b, `*`(`+`(`-`(`*`(`/`(1, 3), `*`(a))), `*`(`/`(2, 3), `*`(b))), `*`(t))))), x(t) = `*`(exp(`+`(`-`(`*`(2, `*`(t...
 

>
 

>
 

> evv := Eigenvectors(A);
 

Typesetting:-mprintslash([`:=`(evv, Vector[column]([[-2], [-2]]), Matrix([[2, 0], [1, 0]]))], [Vector[column](%id = 13819008), Matrix(%id = 14272376)])
 

> u:= <2, 1>;
 

Typesetting:-mprintslash([`:=`(u, Vector[column]([[2], [1]]))], [Vector[column](%id = 13820016)])
 

 

Pick some vector independent of Typesetting:-mrow(Typesetting:-mi( 

> v := < -1,3>;
 

Typesetting:-mprintslash([`:=`(v, Vector[column]([[-1], [3]]))], [Vector[column](%id = 13820520)])
 

> A.v;
 

Typesetting:-mprintslash([Vector[column]([[`/`(20, 3)], [-`/`(11, 3)]])], [Vector[column](%id = 13821096)])
 

> A.v - (-2)*v;
 

Typesetting:-mprintslash([Vector[column]([[`/`(14, 3)], [`/`(7, 3)]])], [Vector[column](%id = 13820736)])
 

This is Typesetting:-mrow(Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mfrac(Typesetting:-mn( Adjust Typesetting:-mrow(Typesetting:-mi( 

> v := v/(7/3);
 

Typesetting:-mprintslash([`:=`(v, Vector[column]([[-`/`(3, 7)], [`/`(9, 7)]]))], [Vector[column](%id = 13820376)])
 

> A.v - (-2)*v;
 

Typesetting:-mprintslash([Vector[column]([[2], [1]])], [Vector[column](%id = 13819224)])
 

This is Typesetting:-mrow(Typesetting:-mi( Tis normalization gives us the 1 in the matrix B below. 

> P := <u|v>;
 

Typesetting:-mprintslash([`:=`(P, Matrix([[2, -`/`(3, 7)], [1, `/`(9, 7)]]))], [Matrix(%id = 15843928)])
 

> B := P^(-1).A.P;
 

Typesetting:-mprintslash([`:=`(B, Matrix([[-2, 1], [0, -2]]))], [Matrix(%id = 7840800)])
 

> zmat := << exp(-2*t) | t*exp(-2*t)>, <0| exp(-2*t)>>;
 

Typesetting:-mprintslash([`:=`(zmat, Matrix([[exp(`+`(`-`(`*`(2, `*`(t))))), `*`(t, `*`(exp(`+`(`-`(`*`(2, `*`(t)))))))], [0, exp(`+`(`-`(`*`(2, `*`(t)))))]]))], [Matrix(%id = 16968224)])
 

> xsol := P.zmat.P^(-1).xno;
 

Typesetting:-mprintslash([`:=`(xsol, Vector[column]([[`+`(`*`(`+`(exp(`+`(`-`(`*`(2, `*`(t))))), `-`(`*`(`/`(2, 3), `*`(t, `*`(exp(`+`(`-`(`*`(2, `*`(t)))))))))), `*`(a)), `*`(`/`(4, 3), `*`(t, `*`(ex...
 

> {x(t)-xsol[1], y(t)-xsol[2]};
 

{`+`(x(t), `-`(`*`(`+`(exp(`+`(`-`(`*`(2, `*`(t))))), `-`(`*`(`/`(2, 3), `*`(t, `*`(exp(`+`(`-`(`*`(2, `*`(t)))))))))), `*`(a))), `-`(`*`(`/`(4, 3), `*`(t, `*`(exp(`+`(`-`(`*`(2, `*`(t))))), `*`(b))))...
 

> subs(dsol, %);
 

{`+`(`*`(exp(`+`(`-`(`*`(2, `*`(t))))), `*`(`+`(b, `*`(`+`(`-`(`*`(`/`(1, 3), `*`(a))), `*`(`/`(2, 3), `*`(b))), `*`(t))))), `*`(`/`(1, 3), `*`(t, `*`(exp(`+`(`-`(`*`(2, `*`(t))))), `*`(a)))), `-`(`*`...
{`+`(`*`(exp(`+`(`-`(`*`(2, `*`(t))))), `*`(`+`(b, `*`(`+`(`-`(`*`(`/`(1, 3), `*`(a))), `*`(`/`(2, 3), `*`(b))), `*`(t))))), `*`(`/`(1, 3), `*`(t, `*`(exp(`+`(`-`(`*`(2, `*`(t))))), `*`(a)))), `-`(`*`...
 

> map(simplify, %);
 

{0}
 

>