kill(all)$
load(eigen)$

appendix: general system 2 differential equations.
peter.vlasschaert@gmail.com  ,26/03/2017

depends(X,t);
depends(Y,t);

pg1:'diff(X,t)= a*X+b*Y;
pg2:'diff(Y,t)= c*X+d*Y;

M1:zeromatrix(2,2);
M1[1,1]:a$
M1[1,2]:b$
M1[2,1]:c$
M1[2,2]:d$

coefficient matrix,pg1,pg2

p0:M1;

general solution' pg1,pg2 '  X=a1*e^(lambda*t)
                             Y=a2*e^(lambda*t)

p1:X=a1*%e^(lambda*t);
p2:Y=a2*%e^(lambda*t);

p3:ev(pg1,p1,p2);
p4:ev(pg2,p1,p2);

p5:ev(p3,nouns)/%e^(t*lambda);
p6:ev(p4,nouns)/%e^(t*lambda);

p7:ratsimp(p5);
p8:ratsimp(p6);

p9:rhs(p7)-lhs(p7)=0;
p10:rhs(p8)-lhs(p8)=0;

p11:coeff(part(p9,1),a1);
p12:coeff(part(p9,1),a2);
p13:coeff(part(p10,1),a1);
p14:coeff(part(p10,1),a2);

build matrix M2 ' coefficient matrix '

M2:zeromatrix(2,2);

M2[1,1]:p11$
M2[1,2]:p12$
M2[2,1]:p13$
M2[2,2]:p14$

coefficient matrix,p9,p10

M2;

solvable : determinant = 0

p15: ratsimp(determinant(M2))=0;

characteristics polynomial of a matrix  M2,'p15'

load("functs")$

needed :tracematrix 'statement'
definition : sum of all elements on diagonal.

p16:tracematrix(M1);

p17:determinant(M1);

lambda^2-tracematrix(M1)*lambda+determinant(M1)=0

p18:lambda^2-tracematrix(M1)*lambda+determinant(M1)=0;

eigenvalues : lambda1,lambda2,see module3
other words : propervalues,char.values

p19:solve(p18,lambda)$

two lambda1: 'p20',lambda2: 'p21'

p20:p19[1];
p21:p19[2];

find eigenvectors a1,a2 -> lambda1
                  a1,a2 -> lambda2

p22:a1*M2[1,1]+a2*M2[1,2]=0;
p23:a1*M2[2,1]+a2*M2[2,2]=0;

lambda1 find 'p20'

p24:ev(p22,p20);
p25:ev(p23,p20);

solve system 'p24,p25' for a1,a2
menu:equations -> solve linear system

p26:linsolve([p24, p25], [a1,a2]);

p27:ev(p26,%r1=1);

lambda2 find 'p21'

p28:ev(p22,p21);
p29:ev(p23,p21);

solve system 'p24,p25' for a1,a2
menu:equations -> solve linear system

p30:linsolve([p28, p29], [a1,a2]);

p31:ev(p30,%r2=1);

see: module3,how to write general solution at the 'end'

missing : repeated eigenvalues. 'comming later'
https://ocw.mit.edu/courses/mathematics/18-03-differential-equations-spring-2010/video-lectures/
lecture-26-continuation-repeated-real-eigenvalues/