kill(all)$

module 2a: solve system : differential equations. 2 by 2
solve : laplace transformation
peter.vlasschaert@gmail.com , 10/10/2017

ps[1]:'diff(x[1],t)=-0.5*x[1]+x[2];
ps[2]:'diff(x[2],t)=0*x[1]-2*x[2];

build coefficient  2 by 2 :ODE

M1:zeromatrix(2,2)$
for i:1 thru 2 do
    for j:1 thru 2 do
  M1[i,j]:coeff(part(ps[i],2),x[j]);;

coefficient matrix ps[1],ps[2]

M1;

method 1 : desolve.

 desolve : x1 => f(x) ,x2 => g(x) , notation needed for use of this method
 =>              solves system of linear ODE using Laplace transform inside
(build command  'desolve')

p1:'diff(f(x),x)  = M1[1,1]*f(x) + M1[1,2]*g(x);
p2:'diff(g(x),x) = M1[2,1]*f(x) + M1[2,2]*g(x);
atvalue(f(x),x=0,a);
atvalue(g(x),x=0,b);

initial condition : f(0) = a, g(0) =b , 'atvalue command'

p3:desolve([p1,p2],[f(x),g(x)])$
p4:p3[1];
p5:p3[2];

check : 'p1,p2'       => f(x),g(x)

p6:ratsimp(ev(p1,p4,p5,diff));
p7:ratsimp(ev(p2,p4,p5,diff));
is(p6);
is(p7);

booean check :  'p6,p7' => true or false

method 2 : Laplace Transformation ODE  2 by 2

depends ([Y],t)$
depends([G],t)$

p1a::'diff(Y,t)  = M1[1,1]*Y+ M1[1,2]*G;
p2a::'diff(G,t)  = M1[2,1]*Y+ M1[2,2]*G;

find    L{Y'(t)} => Y(0) from above 'a'

paa:Y(0) = a;

p11a:ys=laplace(Y(t), t, s);
p22a:laplace(diff(Y(t),t), t, s);
p33a:ev(ratsubst(lhs(p11a), rhs(p11a), p22a),paa);

find    L{G'(t)} => G(0) from above 'b'

pbb:G(0)=b;

p1b:gs=laplace(G(t), t, s);
p2b:laplace(diff(G(t),t), t, s);
p3b:ev(ratsubst(lhs(p1b), rhs(p1b), p2b),pbb);

Take Laplace Transformation 'p1a and p2a' => 'p11b and p22b

p11b:p33a =M1[1,1]*ys+ M1[1,2]*gs;
p22b:p3b   =M1[2,1]*ys+ M1[2,2]*gs;

solve for gs,fs as a system
menu:Equations:Solve.

p1c:solve([p11b,p22b], [ys,gs])[1]$
p2c:p1c[1];
p3c:p1c[2];

find  ys,gs ( s domain)  <=> inverse laplace transform = Y(t), G(t).
 L^(-1){ys} = Y(t)  and  L^(-1){gs} = G(t)

find Y(t) ,G(t).

p1d:Y=ilt(part(p2c,2),s,t);
p2d:G=ilt(part(p3c,2),s,t);

check value Y(t),G(t)  =>  ' p1a and p2a' " ODE  2 by 2"

p3d:ratsimp(ev(p1a,p1d,p2d,diff));
p4d:ratsimp(ev(p2a,p1d,p2d,diff));
is(p3d);
is(p4d);