Systems of Linear Equations

Slides:



Advertisements
Similar presentations
Chapter 2 Solutions of Systems of Linear Equations / Matrix Inversion
Advertisements

Linear Algebra Applications in Matlab ME 303. Special Characters and Matlab Functions.
Algebraic, transcendental (i.e., involving trigonometric and exponential functions), ordinary differential equations, or partial differential equations...
Matrices: Inverse Matrix
MATH 685/ CSI 700/ OR 682 Lecture Notes
1 Copyright © 2015, 2011, 2007 Pearson Education, Inc. Chapter 4-1 Systems of Equations and Inequalities Chapter 4.
SOLVING SYSTEMS OF LINEAR EQUATIONS. Overview A matrix consists of a rectangular array of elements represented by a single symbol (example: [A]). An individual.
Lecture 9: Introduction to Matrix Inversion Gaussian Elimination Sections 2.4, 2.5, 2.6 Sections 2.2.3, 2.3.
Refresher: Vector and Matrix Algebra Mike Kirkpatrick Department of Chemical Engineering FAMU-FSU College of Engineering.
Chapter 9 Gauss Elimination The Islamic University of Gaza
Linear Algebraic Equations
Linear Systems of Equations Ax = b Marco Lattuada Swiss Federal Institute of Technology - ETH Institut für Chemie und Bioingenieurwissenschaften ETH Hönggerberg/
Chapter 2 Basic Linear Algebra
Solving systems using matrices
Matrices and Systems of Equations
Chapter 2 Matrices Definition of a matrix.
ECIV 520 Structural Analysis II Review of Matrix Algebra.
Economics 2301 Matrices Lecture 13.
Ordinary Differential Equations (ODEs) 1Daniel Baur / Numerical Methods for Chemical Engineers / Implicit ODE Solvers Daniel Baur ETH Zurich, Institut.
MOHAMMAD IMRAN DEPARTMENT OF APPLIED SCIENCES JAHANGIRABAD EDUCATIONAL GROUP OF INSTITUTES.
Ordinary Differential Equations (ODEs)
化工應用數學 授課教師: 郭修伯 Lecture 9 Matrices
Ordinary Differential Equations (ODEs) 1Daniel Baur / Numerical Methods for Chemical Engineers / Implicit ODE Solvers Daniel Baur ETH Zurich, Institut.
Matrices and Determinants
Chapter 5 Determinants.
Arithmetic Operations on Matrices. 1. Definition of Matrix 2. Column, Row and Square Matrix 3. Addition and Subtraction of Matrices 4. Multiplying Row.
Copyright © Cengage Learning. All rights reserved. 7.6 The Inverse of a Square Matrix.
Chapter 7 Matrix Mathematics Matrix Operations Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
1 1.1 © 2012 Pearson Education, Inc. Linear Equations in Linear Algebra SYSTEMS OF LINEAR EQUATIONS.
Chapter 10 Review: Matrix Algebra
Spring 2013 Solving a System of Linear Equations Matrix inverse Simultaneous equations Cramer’s rule Second-order Conditions Lecture 7.
Systems and Matrices (Chapter5)
Systems of Linear Equations Iterative Methods
 Row and Reduced Row Echelon  Elementary Matrices.
Rev.S08 MAC 1140 Module 10 System of Equations and Inequalities II.
Slide Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
MA2213 Lecture 5 Linear Equations (Direct Solvers)
Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
Boundary Value Problems and Least Squares Minimization
1 C ollege A lgebra Systems and Matrices (Chapter5) 1.
10.4 Matrix Algebra 1.Matrix Notation 2.Sum/Difference of 2 matrices 3.Scalar multiple 4.Product of 2 matrices 5.Identity Matrix 6.Inverse of a matrix.
Lecture 8 Matrix Inverse and LU Decomposition
Solving Linear Systems of Equations
Linear algebra: matrix Eigen-value Problems Eng. Hassan S. Migdadi Part 1.
Chapter 5 MATRIX ALGEBRA: DETEMINANT, REVERSE, EIGENVALUES.
Chapter 3 Determinants Linear Algebra. Ch03_2 3.1 Introduction to Determinants Definition The determinant of a 2  2 matrix A is denoted |A| and is given.
4.5 Inverse of a Square Matrix
ME 142 Engineering Computation I Matrix Operations in Excel.
Chapter 9 Gauss Elimination The Islamic University of Gaza
Chapter 2 Determinants. With each square matrix it is possible to associate a real number called the determinant of the matrix. The value of this number.
Matrices and Matrix Operations. Matrices An m×n matrix A is a rectangular array of mn real numbers arranged in m horizontal rows and n vertical columns.
Part 3 Chapter 9 Gauss Elimination PowerPoints organized by Dr. Michael R. Gustafson II, Duke University All images copyright © The McGraw-Hill Companies,
LEARNING OUTCOMES At the end of this topic, student should be able to :  D efination of matrix  Identify the different types of matrices such as rectangular,
Section 2.1 Determinants by Cofactor Expansion. THE DETERMINANT Recall from algebra, that the function f (x) = x 2 is a function from the real numbers.
Linear Algebra Engineering Mathematics-I. Linear Systems in Two Unknowns Engineering Mathematics-I.
If A and B are both m × n matrices then the sum of A and B, denoted A + B, is a matrix obtained by adding corresponding elements of A and B. add these.
Matrices, Vectors, Determinants.
1 SYSTEM OF LINEAR EQUATIONS BASE OF VECTOR SPACE.
10.4 Matrix Algebra. 1. Matrix Notation A matrix is an array of numbers. Definition Definition: The Dimension of a matrix is m x n “m by n” where m =
Slide INTRODUCTION TO DETERMINANTS Determinants 3.1.
CHAPTER 7 Determinant s. Outline - Permutation - Definition of the Determinant - Properties of Determinants - Evaluation of Determinants by Elementary.
MAT 322: LINEAR ALGEBRA.
ECE 3301 General Electrical Engineering
5 Systems of Linear Equations and Matrices
Unit 3: Matrices
Numerical Analysis Lecture14.
Matrix Algebra.
Lecture 8 Matrix Inverse and LU Decomposition
Linear Systems of Equations: solution and applications
Presentation transcript:

Systems of Linear Equations Daniel Baur ETH Zurich, Institut für Chemie- und Bioingenieurwissenschaften ETH Hönggerberg / HCI F128 – Zürich E-Mail: daniel.baur@chem.ethz.ch http://www.morbidelli-group.ethz.ch/education/index Daniel Baur / Numerical Methods for Chemical Engineers / Linear Equation Systems

Problem Definition We want to solve the problem where x is the vector of unknowns, while A and b are given Assumptions The number of equations is equal to the number of unknowns, therefore A is a square matrix All components of A, b and x are real A solution exists and it is unique A-1 exists A is not singular A’s columns are linearly independent A’s rows are linearly independent det(A) is non-zero rank(A) is equal to n Ax = 0 only if x is a null vector Daniel Baur / Numerical Methods for Chemical Engineers / Linear Equation Systems

Analytical Approach Cramer’s rule (1750): The solution is given by where Ai is defined as follows b replaces the ith column Daniel Baur / Numerical Methods for Chemical Engineers / Linear Equation Systems

Calculation of the Determinant The Laplace formula (1772) allows the computation of the determinant of a square matrix: where Ci,j is the determinant of the sub-matrix obtained by removing the ith row and the jth column of the matrix, multiplied by (-1)i+j: no jth column no ith row Daniel Baur / Numerical Methods for Chemical Engineers / Linear Equation Systems

A First Numerical Approach: Gauss Elimination Method The following operations do not change the result: Multiply a line by a constant Substitute a line with a linear combination of multiple lines Permute the order of lines This can be used to produce a triangular matrix, which allows the solution to be found easily by substitution Example system Daniel Baur / Numerical Methods for Chemical Engineers / Linear Equation Systems

Gauss Elimination Example Triangular System Multiply by -3 Sum it to 1st line Multiply by -4 Sum it to 2nd line Multiply by -3 Sum it to 1st line Daniel Baur / Numerical Methods for Chemical Engineers / Linear Equation Systems

Generalization of the Gauss Elimination Method We want to find a general procedure to replace one entry in the matrix with a zero; for this we define a multiplier l21 Note that Daniel Baur / Numerical Methods for Chemical Engineers / Linear Equation Systems

The Gauss Elimination in Matrix Notation If we put all multipliers for one column in one matrix, we get where This way, a triangular matrix is easily obtained Daniel Baur / Numerical Methods for Chemical Engineers / Linear Equation Systems

Example: Gauss Elimination in Matrix Notation Total number of operations required (n-1)(n-2) operations (flops) n(n-1) operations (flops) Daniel Baur / Numerical Methods for Chemical Engineers / Linear Equation Systems

Gauss Elimination / Transformation Method The Gauss elimination method is relatively easy to implement (even by hand), but has some distinct disadvantages; namely it Changes the matrix A Requires and changes the coefficient vector b Must be rerun if the vector b changes If we consider the Gauss method in matrix form on the other hand, we can see that we can use to transform A and b; M is therefore called the Gauss transformation matrix Daniel Baur / Numerical Methods for Chemical Engineers / Linear Equation Systems

The Gauss Transformation Method We have so far The final matrix A, which is an right triangular matrix The matrix M, which is a left triangular matrix The inverse of M is also a left triangular matrix Daniel Baur / Numerical Methods for Chemical Engineers / Linear Equation Systems

LR (LU) Factorization We define our (right triangular) solution matrix as follows If we multiply with L = M-1 from the left on both sides Daniel Baur / Numerical Methods for Chemical Engineers / Linear Equation Systems

LR Factorization (Continued) The starting matrix A is transformed (factorized) as If we apply this to a linear equation system, we get This approach rids us of the disadvantages discussed earlier, because For every vector b, two simple triangular systems must be solved without factorizing again The matrices L and R can be stored using the elements of A If A is modified, it is often possible to modify L and R accordingly without re-factorizing Note that Gauss elimination is still needed once to compute L and R Daniel Baur / Numerical Methods for Chemical Engineers / Linear Equation Systems

Pivoting It is easy to see from the definition of the multiplication factors, that the diagonal elements at each step (the pivot values) cannot be equal to zero This is circumvented by reordering the rows of the matrix A by multiplication with a permutation matrix P This approach is referred to as LRP-factorization (or LR-factorization with partial pivoting) Example: a11 = 0  switch the lines  x1 = x2 = 1 Daniel Baur / Numerical Methods for Chemical Engineers / Linear Equation Systems

Pivoting (Continued) Pivoting must also take into account scaling problems; Let us consider a similar example Pivot elements should have large absolute values Daniel Baur / Numerical Methods for Chemical Engineers / Linear Equation Systems

How does Matlab do it? When using left divide \, Matlab chooses a procedure depending on the properties of the problem, i.e. if A is Diagonal, x is computed directly by division Sparse, square and banded, then banded solvers are used; Either Gauss elimination without pivoting or LR factorization Left or right triangular, then backsubstitution is used A permutation of a triangular matrix, it is permuted and 3. applies Symmetric or Hermitian, then a Cholesky factorization is attempted (A = RR*, where R* is the conjugate transpose of R); If it fails, another indefinite symmetric factorization is attempted Square but 1 through 5 do not apply, then LR factorization with partial pivoting is applied Not square, then Householder reflections are used to compute a factorization which leads to a least-squares solution, i.e. a vector x which minimizes the length of Ax – b Daniel Baur / Numerical Methods for Chemical Engineers / Linear Equation Systems

Assignment 1 Find online the template for an LR-factorization of a matrix with partial pivoting. Make the function operational by adding the lines that calculate the M matrix of the current step and the new A matrix. Why does the transformation matrix T appear in the formula for M? Explain by comparing to the definition of M in the non-pivoting case. Use the function to factorize the following matrix Test if the factorization worked, i.e. if LR = A. Is L in the form you would expect it to be? What implications does this have for its application in solving a linear system (see slide 13) and how could you correct for it? Daniel Baur / Numerical Methods for Chemical Engineers / Linear Equation Systems

Hints Daniel Baur / Numerical Methods for Chemical Engineers / Linear Equation Systems

Assignment 2 Create a random matrix A with dimensions 4x4 and a random column vector b with size 4x1. Solve the system Ax = b. Create a function that computes the determinant of square matrices using the Laplace formula. Use a recursive approach (see hints). Use this function to compute the solution of the linear system above using Cramer’s rule. Do the same for linear equation systems with sizes ranging from 5 to 9. Read out the CPU time required to solve all these systems with both methods (Cramer’s method and A\b) and compare them. Daniel Baur / Numerical Methods for Chemical Engineers / Linear Equation Systems

Hints If you remember the Laplace formula as a sum you can see that the calculation of the determinant requires the calculation of a determinant. You could let the function call itself to do that (recursive function). Remember that the determinant of a 1x1 matrix is equal to its only element. There are several Matlab commands to read out timings, however the most reliable one is t_start = tic; statements; t_elapsed = toc(t_start); Where the time elapsed (in second) is stored in t_elapsed Daniel Baur / Numerical Methods for Chemical Engineers / Linear Equation Systems