Linear Algebra with Sage

<Linear System of Equations>


Made by SKKU Linear Algebra Lab (2011)



Solve following LSE using inverse matrix.

@@ \left\{ \begin{array}{ll} x+y+2z=9\\ 2x+4y-3z=1\\ 3x+6y-5z=0 \end{array}\right.@@



<There are 3 cases : Unique solution, Infinitely many solutions, No solution>

The following commands work for the first 2 cases.


Declare variables and input equations (변수 선언과 방정식 입력)

var('x,y,z')

eq1=x+y+2*z==9

eq2=2*x+4*y-3*z==1

eq3=3*x+6*y-5*z==0


Solve the LSE directly (선형 연립 방정식의 직접적인 풀이)

solve([eq1, eq2, eq3], x,y,z)

[[x == 1, y == 2, z == 3]]



And For the unique solution case, we can do solve as following.


Define matrices (계수행렬과 상수행렬 생성 및 확인)

A=matrix([[1,1,2],[2,4,-3],[3,6,-5]]);

v=matrix(3,1,[9,1,0]);

print A

print v

[ 1  1  2]

[ 2  4 -3]

[ 3  6 -5]

[9]

[1]

[0]


Find @@A^{-1} \textbf{v}@@ (Solve for @@\textbf{x}@@ in @@A \textbf{x} = \textbf{v}@@)

A\v

[1]

[2]

[3]