* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download slides
Non-negative matrix factorization wikipedia , lookup
Signal-flow graph wikipedia , lookup
Elementary algebra wikipedia , lookup
Eigenvalues and eigenvectors wikipedia , lookup
Matrix calculus wikipedia , lookup
Horner's method wikipedia , lookup
Polynomial ring wikipedia , lookup
Quartic function wikipedia , lookup
Matrix multiplication wikipedia , lookup
Factorization of polynomials over finite fields wikipedia , lookup
Quadratic equation wikipedia , lookup
Linear algebra wikipedia , lookup
History of algebra wikipedia , lookup
Fundamental theorem of algebra wikipedia , lookup
Gaussian elimination wikipedia , lookup
Quadratic form wikipedia , lookup
Eisenstein's criterion wikipedia , lookup
Cayley–Hamilton theorem wikipedia , lookup
System of polynomial equations wikipedia , lookup
Linear systems of equations and their solution Video 12 Daniel J. Bodony Department of Aerospace Engineering University of Illinois at Urbana-Champaign In this video you will learn. . . 1 What is a linear system of equations? 2 How to write one in matrix form. 3 4 When is there a solution? How to solve A~x = ~b in Matlab. 5 Example: fitting a quadratic polynomial to three points D. J. Bodony (UIUC) AE199 IAC Video 12 2 / 20 What is a linear system of equations? Possibly a long time ago you learned how to solve equations of the type x +y +z =2 2x + 8y = −1 y − 3z = 0. Notice that we have 3 equations with 3 unknowns, x, y , and z. This is a system of equations. Using the rules of matrix-vector multiplication, we can write the same system as x 2 1 1 1 2 8 0 y = −1 z 0 0 1 −3 {z } |{z} | {z } | A ~ x ~ b A~x = ~b D. J. Bodony (UIUC) ← This is in matrix form. AE199 IAC Video 12 3 / 20 Matrix form of linear system of equations The generic equation A~x = ~b is the matrix form of a linear system of equations. We call A the matrix of coefficients, or coefficient matrix ~x the vector of unknowns, or just the unknowns ~b the right-hand-side vector, or just the right-hand-side (rhs). Matlab has a large set of tools useful for solving A~x = ~b. Generically we write the solution as ~x = A−1 ~b; however, A−1 , called the inverse of A, may not exist. D. J. Bodony (UIUC) AE199 IAC Video 12 4 / 20 When is there a solution? Let’s see what conditions on A are important for solving A~x = ~b by way of a 2 × 2 example. Suppose that our equations are ax + by = r1 cx + dy = r2 and we are to solve for ~x = [x y ]T in terms of ~b = [r1 r2 ]T . In matrix form we write this is a b x r = 1 r2 c d y and the solution is −1 x a b r1 = , y c d r2 provided the inverse exists. D. J. Bodony (UIUC) AE199 IAC Video 12 5 / 20 When is there a solution? It is easy to find the inverse of a 2 × 2 matrix; it is a b c d −1 1 d −b = ∆ −c a where ∆ = ad − bc is the determinant of A. From the expression on the right we see clearly that if ∆ = 0 then the inverse does not exist! When ∆ = 0 the matrix A is called singular!1 1 When ∆ = 0 a solution may exist but we will not discuss this in class. D. J. Bodony (UIUC) AE199 IAC Video 12 6 / 20 How to solve A~x = ~b in Matlab Assuming the determinant of A, ∆, is not zero, Matlab will very easily solve A~x = ~b in several ways. The most natural way for you will be to use x = inv(A) * b; ← ~x = A−1 b where inv is the matrix inverse command. How does this command work? 1 The inverse of A is explicitly computed 2 A matrix-vector multiplication between inv(A) and b happens 3 The result is stored in x D. J. Bodony (UIUC) AE199 IAC Video 12 7 / 20 How to solve A~x = ~b in Matlab Matlab provides another way to solve A~x = ~b. It is x = A\b; Notice the use of the backslash (\) command. The (\) is a very special command that Matlab uses to solve a large variety of linear system problems. It works roughly like this: 1 If A is square, then 1 2 2 Look at the structure of A (e.g., symmetric, triangular, ...) and pick a good solution method Store the solution in x Else, use a least squares method if A is rectangular and store the solution in x. D. J. Bodony (UIUC) AE199 IAC Video 12 8 / 20 Choosing inv(A)*b or A\b How do you choose? Well, the answer is trivial: ALWAYS CHOOSE A\b Why? Let me count the ways 1 A\b is faster because it doesn’t compute the inverse of A directly (you’ll learn more about this in AE370) 2 A\b works even if A is singular (we won’t discuss this) 3 A\b works even if A is rectangular (we won’t discuss this) D. J. Bodony (UIUC) AE199 IAC Video 12 9 / 20 Example: quadratic polynomial fit To illustrate things, let’s do a simple example of finding the coefficients of a quadratic polynomial p(x) = ax 2 + bx + c that exactly go through the three points in the x-y plane (x1 , y1 ), (x2 , y2 ) and (x3 , y3 ). What do we mean by ‘go through the three points’ ? We mean the value of the polynomial p(x) at the points xi is exactly equal to yi , for i = 1, 2, 3. That is we want to find the {a, b, c} such that p(x1 ) = y1 p(x2 ) = y2 p(x3 ) = y3 D. J. Bodony (UIUC) AE199 IAC Video 12 10 / 20 Example: quadratic polynomial fit Using the definition of the polynomial p(x) we find three equations in the three unknowns {a, b, c}: ax12 + bx1 + c = y1 ax22 + bx2 + c = y2 ax32 + bx3 + c = y3 or, in matrix form, 2 x1 x1 1 a y1 x22 x2 1 b = y2 x32 x3 1 c y3 or A~x = ~b. D. J. Bodony (UIUC) AE199 IAC Video 12 11 / 20 Example: quadratic polynomial fit For real numbers, let’s find the polynomial that passes through the three red points that lie on the cosine: (2, cos 2), (π, cos π), (4, cos 4). 1.5 1 0.5 0 −0.5 −1 −1.5 0 D. J. Bodony (UIUC) 1 2 3 AE199 IAC 4 5 6 Video 12 12 / 20 Example: quadratic polynomial fit In this example we have (x1 , y1 ) = (2, cos 2) (x2 , y2 ) = (π, cos π) (x3 , y3 ) = (4, cos 4) so that our matrix A and vector ~b are 4 2 1 cos 2 A = π 2 π 1 and ~b = cos π 16 4 1 cos 4 It is easy to check that det(A) = -1.9599 and so we expect a solution. D. J. Bodony (UIUC) AE199 IAC Video 12 13 / 20 Example: quadratic polynomial fit Once A and b are entered into Matlab, we can find the answer using \: >> format long e >> x = A\b x = 4.574622948019237e-01 -2.863522160969777e+00 3.481048306184716e+00 So, according to Matlab, the polynomial we are after is p(x) = (4.574622948019237 × 10−1 )x 2 + (−2.863522160969777 × 100 )x + (3.481048306184716 × 100 ) D. J. Bodony (UIUC) AE199 IAC Video 12 14 / 20 Example: quadratic polynomial fit A plot of the polynomial fit (in black) shows that it performs as desired. 1.5 1 0.5 0 −0.5 −1 −1.5 0 D. J. Bodony (UIUC) 1 2 3 AE199 IAC 4 5 6 Video 12 15 / 20 Example: quadratic polynomial fit We can check our answer by using polyfit in Matlab: >> polyfit([2 pi 4],cos([2 pi 4]),2).’ ans = 4.574622948019231e-01 -2.863522160969772e+00 3.481048306184707e+00 Which is the same to 14 decimal places. (Matlab uses a different algorithm within polyfit so the coefficients are different to within numerical roundoff.) D. J. Bodony (UIUC) AE199 IAC Video 12 16 / 20 Another example: bunch of linear springs Let’s start simple by having one spring only, as shown in the figure: A force balance says that k1 x = W so that x = k1−1 W . (Notice the way I’ve written this.) D. J. Bodony (UIUC) AE199 IAC Video 12 17 / 20 Another example: bunch of linear springs Add another spring so that our picture looks like Our goal: find x given W . D. J. Bodony (UIUC) AE199 IAC Video 12 18 / 20 We start by identifying the equilibrium lengths of the springs as x1e and x2e when no weight is on the platform: Undeformed Deformed We perform a force balance on the platform (top red box) to find that k1 (x1 − x1e ) − W = 0 and a force balance on the inter-spring connection (bottom red box) to get k2 (x2 − x2e ) − k1 (x1 − x1e ) = 0. D. J. Bodony (UIUC) AE199 IAC Video 12 19 / 20 Another example: bunch of linear springs If we define the change in length of the springs as δ1 = x1 − x1e δ2 = x2 − x2e then our linear system can be written in matrix form as k1 0 δ1 W = −k1 k2 δ2 0 which has solution W k2 1 k2 0 W δ1 = = 0 δ2 k1 k2 k1 k1 k1 k2 k1 such that the total displacement of platform is x = δ1 + δ2 = W D. J. Bodony (UIUC) AE199 IAC k1 + k2 k1 k2 Video 12 20 / 20