Copyright © 2005. The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.

Slides:



Advertisements
Similar presentations
Elementary Linear Algebra
Advertisements

MAT 105 FALL 2008 Graphs of Linear Functions
Chapter 2 Solutions of Systems of Linear Equations / Matrix Inversion
Linear Algebra Applications in Matlab ME 303. Special Characters and Matlab Functions.
Systems of Linear Equations
SOLVING SYSTEMS OF LINEAR EQUATIONS. Overview A matrix consists of a rectangular array of elements represented by a single symbol (example: [A]). An individual.
12.1 Systems of Linear Equations: Substitution and Elimination.
Lesson 8 Gauss Jordan Elimination
Chapter 9 Gauss Elimination The Islamic University of Gaza
Dan Witzner Hansen  Groups?  Improvements – what is missing?
Chapter 2 Basic Linear Algebra
Chapter 2 Section 4 The Inverse Matrix. Problem Find X in the a matrix equation: A X = B (recall that A is the matrix of the coefficients, X is the matrix.
Matrices and Systems of Equations
Chapter 1 Systems of Linear Equations
Math for CSLecture 21 Solution of Linear Systems of Equations Consistency Rank Geometric Interpretation Gaussian Elimination Lecture 2. Contents.
10.1 Gaussian Elimination Method
Part 3 Chapter 8 Linear Algebraic Equations and Matrices PowerPoints organized by Dr. Michael R. Gustafson II, Duke University All images copyright © The.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. by Lale Yurttas, Texas A&M University Part 31 Chapter.
Linear Simultaneous Equations
Matrix Mathematics in MATLAB and Excel
Copyright © Cengage Learning. All rights reserved. 7.6 The Inverse of a Square Matrix.
Non-Linear Simultaneous Equations
5  Systems of Linear Equations: ✦ An Introduction ✦ Unique Solutions ✦ Underdetermined and Overdetermined Systems  Matrices  Multiplication of Matrices.
Introduction Information in science, business, and mathematics is often organized into rows and columns to form rectangular arrays called “matrices” (plural.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 ~ Linear Algebraic Equations ~ Gauss Elimination Chapter.
LIAL HORNSBY SCHNEIDER
© 2005 Baylor University Slide 1 Fundamentals of Engineering Analysis EGR 1302 Unit 1, Lecture F Approximate Running Time - 24 minutes Distance Learning.
Precalculus – MAT 129 Instructor: Rachel Graham Location: BETTS Rm. 107 Time: 8 – 11:20 a.m. MWF.
1. Copyright © 2006 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Systems of Equations CHAPTER 9.1Solving Systems of Linear Equations Graphically.
Systems of Equations and Inequalities
1 1.1 © 2012 Pearson Education, Inc. Linear Equations in Linear Algebra SYSTEMS OF LINEAR EQUATIONS.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
Professor Dr. S. K. Bhattacharjee Department of Statistics
Copyright © 2013, 2009, 2005 Pearson Education, Inc. 1 5 Systems and Matrices Copyright © 2013, 2009, 2005 Pearson Education, Inc.
ENGR-25_Linear_Equations-1.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.
Chapter 1 – Linear Equations
Chapter 10 Review: Matrix Algebra
Introduction to MATLAB for Engineers, Third Edition William J. Palm III Chapter 8 Linear Algebraic Equations PowerPoint to accompany Copyright © 2010.
Linear Equations in Linear Algebra
MATRICES AND DETERMINANTS
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
Systems and Matrices (Chapter5)
System of Linear Equations Nattee Niparnan. LINEAR EQUATIONS.
Copyright © 2000 by the McGraw-Hill Companies, Inc. Barnett/Ziegler/Byleen Precalculus: A Graphing Approach Chapter Eight Systems: Matrices.
Systems of Linear Equation and Matrices
CALCULUS – II Gauss Elimination
Presentation by: H. Sarper
ME 1202: Linear Algebra & Ordinary Differential Equations (ODEs)
Copyright © 2013, 2009, 2005 Pearson Education, Inc. 1 5 Systems and Matrices Copyright © 2013, 2009, 2005 Pearson Education, Inc.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
8.1 Matrices & Systems of Equations
ENE MATHLAB ® Lecture 3: Matrix Review. Determinant  To use MATLAB to compute determinants:  Enter the determinant as an array.  Use ‘det’ command.
Systems of Equations and Inequalities Systems of Linear Equations: Substitution and Elimination Matrices Determinants Systems of Non-linear Equations Systems.
Solving Linear Systems of Equations
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 3 - Chapter 9 Linear Systems of Equations: Gauss Elimination.
Section 2.3 Properties of Solution Sets
Chapter 9 Gauss Elimination The Islamic University of Gaza
Slide Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley A set of equations is called a system of equations. The solution.
Introduction to MATLAB 7
Copyright ©2015 Pearson Education, Inc. All rights reserved.
Part 3 Chapter 9 Gauss Elimination PowerPoints organized by Dr. Michael R. Gustafson II, Duke University All images copyright © The McGraw-Hill Companies,
Copyright © 2014, The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Matrices, Vectors, Determinants.
1 SYSTEM OF LINEAR EQUATIONS BASE OF VECTOR SPACE.
Copyright © Cengage Learning. All rights reserved. 8 Matrices and Determinants.
5 Systems of Linear Equations and Matrices
Chapter 10: Solving Linear Systems of Equations
Lial/Hungerford/Holcomb/Mullins: Mathematics with Applications 11e Finite Mathematics with Applications 11e Copyright ©2015 Pearson Education, Inc. All.
6 Systems of Linear Equations and Matrices
Presentation transcript:

Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm III Chapter 6 Linear Algebraic Equations PowerPoint to accompany

AGENDA Solving "well behaved" Systems of Equations Solving "well behaved" Systems of Equations Gauss Elimination Gauss Elimination Matrix form and Matlab Matrix form and Matlab Cramer's Method Cramer's Method Applications Applications Existence and Uniqueness of Solutions Existence and Uniqueness of Solutions Underdetermined Systems Underdetermined Systems Overdetermined Systems Overdetermined Systems

Several methods are available for solving linear algebraic equations by hand. The appropriate choice depends on user preference, on the number of equations, and on the structure of the equations to be solved. We demonstrate two methods: 1.Successive (Gaussian) elimination of variables 2.Cramer’s method (in Section 6.3). The MATLAB method is based on the successive elimination technique, but Cramer’s method gives us some insight into the existence and uniqueness of solutions and into the effects of numerical inaccuracy. 6-2 More? See pages

Gauss Elimination try this: LinearEqDemos.m This method involves adding scaled equations to reduce the unknowns: This method involves adding scaled equations to reduce the unknowns: x + 2y = 3 (1) x + 2y = 3 (1) 3x + 4y = 5 (2) 3x + 4y = 5 (2) We can take -3*(eq1) and get We can take -3*(eq1) and get -3x - 6y = -9 (3) Adding (3) and (2) gives: Adding (3) and (2) gives: 0x + -2y = -4 (3) or, y = 2, and x=-1

Existence and Uniqueness In general, for a system of equations, there may be In general, for a system of equations, there may be One unique solution  today One unique solution  today No solution  thursday No solution  thursday An Infinite number of solutions  thursday An Infinite number of solutions  thursday

Matrix Notation multiple equations can be reformated as a single matrix equation. For example, consider the following set: 2x 1  9x 2  5 (6.2–1)‏ 3x 1  4x 2  7 (6.2–2)‏ This set can be expressed in vector-matrix form as which can be represented in the following compact form Ax  b (6.2–3)‏  4 x1x2x1x2  More? See pages

MATLAB provides the left-division method for solving the equation set Ax  b. The left-division method is based on Gauss elimination. To use the left-division method to solve for x, type x = A\b. For example, >> A = [6, -10; 3, -4]; b = [2; 5]; >> x = A\b x = 74 This method also works in some cases where the number of unknowns does not equal the number of equations More? See pages

Matrix Inverse The identity matrix is a matrix of all 1's in the main diagonal: The identity matrix is a matrix of all 1's in the main diagonal: I = The inverse of A is the matrix that will produce I when multiplied by A: The inverse of A is the matrix that will produce I when multiplied by A: Ainverse * A = I Ainverse * A = I

The MATLAB command inv(A) computes the inverse of the matrix A. The following MATLAB session solves the following equations using MATLAB. 2x  9y  5 3x  4y  7 >>A = [2,9;3,-4]; >>b = [5;7] >>x = inv(A)*b x = If you attempt to solve a singular problem using the inv command, MATLAB displays an error message More? See pages

The Determinant A special number associated with a square matrix A special number associated with a square matrix if matrix A = if matrix A = det(A) = 1*4 - 3*2 det(A) = 1*4 - 3*2 + -

Definition: Determinant In algebra, the determinant is a special number associated with any square matrix. The fundamental geometric meaning of a determinant is a scale factor or coefficient for measure when the matrix is regarded as a linear transformation. Thus a 2 × 2 matrix with determinant 2 when applied to a set of points with finite area will transform those points into a set with twice the area. Determinants are important both in calculus, where they enter the substitution rule for several variables, and in multilinear algebra. In algebra, the determinant is a special number associated with any square matrix. The fundamental geometric meaning of a determinant is a scale factor or coefficient for measure when the matrix is regarded as a linear transformation. Thus a 2 × 2 matrix with determinant 2 when applied to a set of points with finite area will transform those points into a set with twice the area. Determinants are important both in calculus, where they enter the substitution rule for several variables, and in multilinear algebra.algebrasquare matrixscale factorcoefficient measurelinear transformationcalculus substitution rule multilinear algebra square matrixscale factorcoefficient measurelinear transformationcalculus substitution rule multilinear algebra

Cramer's Method 1. Calculate detA = det(A) 2. Replace column 1 of A with b and recalculate determinant, detAmod1 3. x1 = detAmod1/detA 4. Repeat with each column to solve for each unknown

Cramer's Method in Action For example, consider the following set: 2x 1  9x 2  5 3x 1  4x 2  7 This set can be expressed in vector-matrix form as which can be represented in the following compact form Ax  b  4 x1x2x1x2  More? See pages

Cramer's Method in Action (cont) So we have a system of equations Ax  b where A = and b = and our solution vector x = Cramer's Method says: x1 = det ( ) / det( ) x2 = det ( ) / det( ) x1x2x1x      

Cramer’s Method Solves equations using determinants. Gives insight into the existence and uniqueness of solutions and into the effects of numerical inaccuracy. Cramer’s determinant D is the determinant of the matrix A in the matrix form Ax = b. D = |A|. When the number of variables equals the number of equations, a singular problem can be identified by computing Cramer’s determinant D. If the determinant D is zero, the equations are singular because D appears in the denominator of the solutions More? See pages

Cramer’s Determinant and Singular Problems For the set 3x - 4y = 5 6x - 8y = 3 Cramer’s determinant is D = 3(-8) – (6)(-4) = 0 Because D = 0, the equation set is singular

Cramer’s determinant gives some insight into ill- conditioned problems, which are close to being singular. A Cramer’s determinant close to zero indicates an ill-conditioned problem More? See pages

Applications of Linear Systems of Equations Connecting two points with a line Connecting two points with a line Connecting three points with a quadratic Connecting three points with a quadratic Designing a ski ramp based on various required geometries Designing a ski ramp based on various required geometries

Find the Line Q: Suppose we wish to connect points Q: Suppose we wish to connect points (3, 4) and (-2, 8) with the straight line (3, 4) and (-2, 8) with the straight line y = mx + b y = mx + b A: Set up a system of equations— A: Set up a system of equations— m*3 + b = 4 m*3 + b = 4 m*(-2) + b = 8 m*(-2) + b = 8 Use left division to find m and b Use left division to find m and b

Find the Quadratic You can even use derivatives You can even use derivatives Q: Find the quadratic y = a x 2 + bx + c that: Q: Find the quadratic y = a x 2 + bx + c that: a) passes through point (3, 5) a) passes through point (3, 5) b) has a minimum at (1,2) how to get 3 eqns? b) has a minimum at (1,2) how to get 3 eqns? A: note taking the derivative gives slope s, A: note taking the derivative gives slope s, s = 2a x + b which = 0 at a minimum s = 2a x + b which = 0 at a minimum 3 equations: 3 equations: a*3*3 + b*3 + c = 5 a*3*3 + b*3 + c = 5 a*1*1 + b*1 + c = 2 a*1*1 + b*1 + c = 2 a*1 + b = 0 a*1 + b = 0 Plug and chug! Plug and chug!

Existence and Uniqueness In general, for a system of equations, there may be In general, for a system of equations, there may be One unique solution One unique solution No solution No solution An Infinite number of solutions An Infinite number of solutions

One Solution The equations 6x – 10y = 2 3x – 4y = 5 have graphs that intersect at the solution y = 4, x =

The graphs of two equations that intersect at a solution. Figure 6.1–1 6-5

No Solution the equations 3x  4y  5 (6.1–6)‏ 6x  8y  3 (6.1–7)‏ has no solution. The graphs of these two equations are distinct but parallel (see Figure 6.1–2). Because they do not intersect, no solution exists. 6-4

Parallel graphs indicate that no solution exists. Figure 6.1–2 6-6

the set 3x  4y  5 6x  8y  10 has no unique solution because the second equation is identical to the first equation, multiplied by 2. The graphs of these two equations are identical. All we can say is that the solution must satisfy y  (3x  5)/4, which describes an infinite number of solutions. 6-3 Infinite Solutions More? See pages

A singular problem refers to a set of equations having either no unique solution or no solution at all. This is the case for both: 3x  4y  5 6x  8y  10 (no unique soln, ∞ solns ) AND 3x  4y  5 6x  8y  3 (no solution) The key? Matrix of coefficients has a determinant of Singular Problem More? See pages

Underdetermined Systems An underdetermined system does not contain enough information to solve for all of the unknown variables, usually because it has fewer equations than unknowns. Thus an infinite number of solutions can exist, with one or more of the unknowns dependent on the remaining unknowns. For such systems the matrix inverse method and Cramer’s method will not work. 6-19

A simple example of an underdetermined systems is the equation x  3y  6 All we can do is solve for one of the unknowns in terms of the other; for example, x  6  3y. An infinite number of solutions satisfy this equation. When there are more equations than unknowns, the left-division method will give a solution with some of the unknowns set equal to zero. For example, >>A = [1, 3]; b = 6; >>solution = A\b solution = 0 2 which corresponds to x = 0 and y =

An infinite number of solutions might exist even when the number of equations equals the number of unknowns. This situation can occur when  A  0. For such systems the matrix inverse method and Cramer’s method will not work, and the left-division method generates an error message warning us that the matrix A is singular. In such cases the pseudoinverse method x = pinv(A)*b gives one solution, the minimum norm solution. 6-21

In cases that have an infinite number of solutions, some of the unknowns can be expressed in terms of the remaining unknowns, whose values are arbitrary. We can use the rref command to find these relations. See slide

Existence and uniqueness of solutions. The set Ax  b with m equations and n unknowns has solutions if and only if rank[A]  rank[A b] (1) Let r  rank[A]. ● If condition (1) is satisfied and if r  n, then the solution is unique. ● If condition (1) is satisfied but r  n, an infinite number of solutions exists and r unknown variables can be expressed as linear combinations of the other n  r unknown variables, whose values are arbitrary. 6-23

Homogeneous case. The homogeneous set Ax  0 is a special case in which b  0. For this case rank[A]  rank[A b] always, and thus the set always has the trivial solution x  0. A nonzero solution, in which at least one unknown is nonzero, exists if and only if rank[A]  n. If m  n, the homogeneous set always has a nonzero solution. 6-24

Recall that if  A  0, the equation set is singular. If you try to solve a singular set using MATLAB, it prints a message warning that the matrix is singular and does not try to solve the problem. 6-25

An ill-conditioned set of equations is a set that is close to being singular. The ill-conditioned status depends on the accuracy with which the solution calculations are made. When the internal numerical accuracy used by MATLAB is insufficient to obtain a solution, MATLAB prints a message to warn you that the matrix is close to singular and that the results might be inaccurate More? See pages

The pinv command can obtain a solution of an underdetermined set. To solve the equation set Ax  b using the pinv command, type x = pinv(A)*b Underdetermined sets have an infinite number of solutions, and the pinv command produces a solution that gives the minimum value of the Euclidean norm, which is the magnitude of the solution vector x More? See pages

A Statically indeterminate problem. A light fixture and its free-body diagram. Example Figure 6.4–1 6-28

The rref function. We can always express some of the unknowns in an underdetermined set as functions of the remaining unknowns. We can obtain such a form by multiplying the set’s equations by suitable factors and adding the resulting equations to eliminate an unknown variable. The MATLAB rref function provides a procedure to reduce an equation set to this form, which is called the reduced row echelon form. The syntax is rref([A b]). The output is the augmented matrix [C d] that corresponds to the equation set Cx  d. This set is in reduced row echelon form More? See pages

Overdetermined Systems. An overdetermined system is a set of equations that has more independent equations than unknowns. For such a system the matrix inverse method and Cramer’s method will not work because the A matrix is not square. However, some overdetermined systems have exact solutions, and they can be obtained with the left division method x = A\b. 6-31

For other overdetermined systems, no exact solution exists. In some of these cases, the left-division method does not yield an answer, while in other cases the left-division method gives an answer that satisfies the equation set only in a “least squares” sense, as explained in Example 6.5–1. When MATLAB gives an answer to an overdetermined set, it does not tell us whether the answer is the exact solution. 6-32

Illustration of the least squares criterion. Figure 6.5–1 6-33

The least squares fit for the example data. Example Figure 6.5– More? See pages

Some overdetermined systems have an exact solution. The left-division method sometimes gives an answer for overdetermined systems, but it does not indicate whether the answer is the exact solution. We need to check the ranks of A and [A b] to know whether the answer is the exact solution. 6-35

To interpret MATLAB answers correctly for an overdetermined system, first check the ranks of A and [A b] to see whether an exact solution exists; if one does not exist, then you know that the left-division answer is a least squares solution. 6-36

Overdetermined problem

Solving Linear Equations: Summary If the number of equations in the set equals the number of unknown variables, the matrix A is square and MATLAB provides two ways of solving the equation set Ax  b: 1. The matrix inverse method; solve for x by typing x = inv(A)*b. 2. The matrix left-division method; solve for x by typing x = A\b (continued …)‏

Solving Linear Equations: Summary (continued)‏ If A is square and if MATLAB does not generate an error message when you use one of these methods, then the set has a unique solution, which is given by the left-division method. You can always check the solution for x by typing A*x to see if the result is the same as b (continued …)‏

Solving Linear Equations: Summary (continued)‏ If you receive an error message, the set is underdetermined, and either it does not have a solution or it has more than one solution. In such a case, if you need more information, you must use the following procedures (continued …)‏

Solving Linear Equations: Summary (continued)‏ For underdetermined and overdetermined sets, MATLAB provides three ways of dealing with the equation set Ax  b. (Note that the matrix inverse method will never work with such sets.)‏ The matrix left-division method; solve for x by typing x = A\b. The pseudoinverse method; solve for x by typing x = pinv(A)*b. 3. The reduced row echelon form (RREF) method. This method uses the MATLAB function rref to obtain a solution (continued …)‏

Solving Linear Equations: Summary (continued)‏ Underdetermined Systems In an underdetermined system not enough information is given to determine the values of all the unknown variables.  An infinite number of solutions might exist in which one or more of the unknowns are dependent on the remaining unknowns.  For such systems Cramer’s method and the matrix inverse method will not work because either A is not square or because  A  (continued …)‏

Solving Linear Equations: Summary (continued)‏  The left-division method will give a solution with some of the unknowns arbitrarily set equal to zero, but this solution is not the general solution.  An infinite number of solutions might exist even when the number of equations equals the number of unknowns. The left-division method fails to give a solution in such cases.  In cases that have an infinite number of solutions, some of the unknowns can be expressed in terms of the remaining unknowns, whose values are arbitrary. The rref function can be used to find these relations (continued …)‏

Solving Linear Equations: Summary (continued)‏ Overdetermined Systems An overdetermined system is a set of equations that has more independent equations than unknowns.  For such a system Cramer’s method and the matrix inverse method will not work because the A matrix is not square.  Some overdetermined systems have exact solutions, which can be obtained with the left-division method A\b (continued …)‏

Solving Linear Equations: Summary (continued)‏  For overdetermined systems that have no exact solution, the answer given by the left-division method satisfies the equation set only in a least squares sense.  When we use MATLAB to solve an overdetermined set, the program does not tell us whether the solution is exact. We must determine this information ourselves. The first step is to check the ranks of A and [A b] to see whether a solution exists; if no solution exists, then we know that the left-division solution is a least squares answer More? See pages

If the rank of A equals the rank of [A b], then determine whether the rank of A equals the number of unknowns. If so, there is a unique solution, which can be computed using left division. Display the results and stop. 2. Otherwise, there is an infinite number of solutions, which can be found from the augmented matrix. Display the results and stop. 3. Otherwise (if the rank of A does not equal the rank of [A b]), then there are no solutions. Display this message and stop. Pseudocode for the linear equation solver. Table 6.6–2 6-45

Flowchart of the linear equation solver. Figure 6.6–1 6-46

% Script file lineq.m % Solves the set Ax = b, given A and b. % Check the ranks of A and [A b]. if rank(A) == rank([A b])‏ % The ranks are equal. Size_A = size(A); % Does the rank of A equal the number of unknowns? if rank(A) == size_A(2)‏ % Yes. Rank of A equals the number of unknowns. disp('There is a unique solution, which is:')‏ x = A\b % Solve using left division. MATLAB program to solve linear equations. Table 6.6– (continued…)‏

Linear equation solver (continued) else % Rank of A does not equal the number of unknowns. disp('There is an infinite number of solutions.')‏ disp('The augmented matrix of the reduced system is:')‏ rref([A b]) % Compute the augmented matrix. end else % The ranks of A and [A b] are not equal. disp('There are no solutions.')‏ end 6-48