Linear Systems of Algebraic Equations Solve a system
Linear Systems of Algebraic Equations Solve a system of n simultaneous linear algebraic equations for n unknowns, x 1, x 2, … , xn: • Problems in science, engineering, economics, etc. • Systems of non-linear equations → linear equations • Numerical methods needed for systems larger than 4× 4
Linear Systems of Algebraic Equations Solve a system of n simultaneous linear algebraic equations for n unknowns, x 1, x 2, … , xn: The system has infinitely many solutions The system has a single unique solution The system has no solution
Linear Systems in a Matrix/Vector form
Solving the Example in MATLAB In MATLAB we can solve the example with the single command x = Ab. To do that we need to type: >> A = [1 1 1; 2 1 3; 3 1 6]; >> b = [4; 7; 2]; >> x = Ab x= 19. 0000 -7. 0000 -8. 0000
Elimination methods for solving Linear Systems • Gaussian elimination The basic idea is to use a sequence of operations that converts the original system into a simpler, but equivalent system that may be solved easily.
Straightforward Systems
Straightforward Systems
Back/Forward-substitution Diagonal: Upper triangular: Lower triangular:
Elimination methods for solving Linear Systems • Gaussian elimination The basic idea is to use a sequence of operations that converts the original system into a simpler, but equivalent system that may be solved easily.
Elementary Row Calculations • Adding two rows (i. e. , two equations) • Multiplying a scalar to a row • Combining the two k c x i + k
Elementary Row Calculations cxi+k→k
Augmented Matrix
Gaussian Elimination
Algorithm for Gaussian Elimination Given that matrix A is n×n we have: for j = 1: N-1 (iterate over columns from left to right) for i = j+1: N (iterate over rows below diagonal) if ai, j = 0 STOP (to avoid division by zero) λ = ai, j/ai, i for k = j: N (iterate in row i from column j to right) ai, k = ai, k – λaj, k end bi = bi – λbj end Number of FLOPS = 2/3 N 3
Gauss-Jordan Elimination
Partial Pivoting However if , then
Partial Pivoting
Algorithm for GE including partial pivoting for j = 1: N-1 (iterate over columns from left to right) select row j such that |aj, i| = max {|ai, i|, |ai+1, i|, . . . , |a. N, 1|} if aj, i = 0, no unique solution exists, STOP if j ≠ i, interchange rows i and j of augmented matrix for i = j+1: N (iterate over rows below diagonal) λ = ai, j/ai, I for k = j: N (iterate in row i from column j to right) ai, k = ai, k – λaj, k end bi = bi – λbj end
Matrix Factorization: LU decomposition • Advantageous when we have systems that have the same left-hand-side (i. e. , only vector b) • With Gaussian elimination we would have to solve all the systems using the same number of calculations.
Matrix Factorization: LU decomposition • Let us assume that we can decompose A into a product of a lower L and upper U triangular matrix: we can obtain the solution by solving two triangular problems
LU Decomposition using Gauss Elimination
LU Decomposition with Pivoting • Pivoting may be required for the successful execution of the Gaussian elimination procedure in finding L and U • To store all the information about the pivoting we use a permutation matrix P so that
Matrix Inversion
Calculating the Inverse of a Matrix 1 st system:
Solving Systems of Linear Eqs. in Matlab
Solving the Example in MATLAB In MATLAB we can solve the example with the single command x = Ab. To do that we need to type: >> A = [1 1 1; 2 1 3; 3 1 6]; >> b = [4; 7; 2]; >> x = Ab x= 19. 0000 -7. 0000 -8. 0000
Solving the Example in MATLAB In MATLAB we can solve the example with the single command x = Ab. To do that we need to type: >> A = [1 1 1; 2 1 3; 3 1 6]; >> b = [4; 7; 2]; >> Ainv = inv(A); >> x = Ainv*b x= 19. 0000 -7. 0000 -8. 0000
Solving the Example in MATLAB In MATLAB we can solve a linear system using LU decomposition with the command lu as follows: >> A = [1 1 1; 2 1 3; 3 1 6]; >> b = [4; 7; 2]; >> [L, U, P] = lu(A) L=… U=… P=… >> c = L(P*b) c=… >> x = Uc x=…
Solving the Example in MATLAB In MATLAB we can perform LU factorization with the command lu: >> A = [1 1 1; 2 1 3; 3 1 6]; >> [L, U, P] = lu(A) L = …, U = …, P = … >> b = [4; 7; 2]; >> x = U(L(P*b)) x= 19. 0000 -7. 0000 -8. 0000
The Determinant If det(A) ≠ 0, (i. e. , A is nonsingular) then the system has a unique solution: Cramer’s method
- Slides: 33