kill(all)$

load(eigen)$

module 2: solve system : differential equations. 2 by 2
peter.vlasschaert@gmail.com , 25/03/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];

M1:zeromatrix(2,2);

find coef ps[1] => x1,x2

p1:coeff(part(ps[1],2),x[1]);
p2:coeff(part(ps[1],2),x[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 (from differential equations): ps[1],ps[2].

M1;

[vals, vecs] : uniteigenvectors (M1);

=> eigenvalues :

p3:vals;

values :

p4:part(vals,1)[1];
p5:part(vals,1)[2];

multiplicities 'values':

p41:part(vals,2)[1];
p51:part(vals,2)[2];

=> uniteigenvectors :

p6:part(vecs,1)[1];
p7:part(vecs,2)[1];

=> build matrix 'eigenvectors,column format'
math : A

p8:transpose(matrix(p6,p7));

=> build from p8 => 'invert(p8)'
math : A^(-1)

p9:invert(p8);

p10:diagmatrix(2,1);

for i:1 thru 2 do 
    p10[i][i]:e^((part(vals,1)[i])*t);

Matrix exponential '2 by 2'
math : e^(At),A = matrix 'diagonal matrix'

p10;

product : three matrix multiplied
math : A*e^(At)*A^(-1)

p12:float(p8*p10*p9);

intial values : need for IVP 'see module 1'

x0[1,1]:1;
x0[1,2]:0;
p13:transpose(genmatrix(x0,1,2,1,1))$

intial value (IVP): vector

p13;

solution : system of differential equations.(ps[1],ps[2])
math: A*e^(At)*A^(-1)*x0 , x0 = 'vector'

p14:p12.p13;

p15:x[1]= p14[1,1];
p16:x[2]= p14[2,1];

check : first differential equation :  ps(1)

p17:ev('diff(part(p15,2),t)=part(p16,2)-0.5*part(p15,2),nouns);

how to bring in e to %e =2.7....

p18:float(-log(%e)/2);

p18:ev(p17,e=%e);

rem : '.' used multiply matrix with vector

module 2:

statement : zeromatrix,genmatrix,diagmatrix,transpose,uniteigenvectors
            ,invert,nouns,coeff.