Applied Linear Algebra in Geoscience Using MATLAB (Linear equations)
Contents Getting Started Creating Arrays Mathematical Operations with Arrays Using Script Files and Managing Data Two-Dimensional Plots Programming in MATLAB User-Defined Functions and Function Files Polynomials, Curve Fitting, and Interpolation Applications in Numerical Analysis Three-Dimensional Plots Symbolic Math Matrices Linear equations Determinants Eigenvalues and eigenvectors Orthogonal vectors and matrices Vector and matrix norms Gaussian elimination and the LU dec. Linear system applications Gram-Schmidt decomposition The singular value decomposition Least-squares problems Implementing the QR factorization The algebraic eigenvalue problem
Recap The system of three equations with three unknowns EX.1
Introduction to Linear Equation A system of n linear equations in n unknowns x 1, x 2,..., x n is a family of equations We wish to determine if such a system has a solution, that is to find out if there exist numbers x 1, x 2,..., x n that satisfy each of the equations simultaneously. We say that the system is consistent if it has a solution. Otherwise, the system is called inconsistent. Geometrically, solving a system of linear equations in two (or three) unknowns is equivalent to determining whether or not a family of lines (or planes) has a common point of intersection. coefficient matrix augmented matrix upper triangular
Introduction to Linear Equation Find a polynomial of degree three, which passes through the points: ( 3, 2), ( 1, 2), (1, 5), (2, 1) AX = b
Row equivalence Matrix A is row-equivalent to matrix B if B is obtained from A by a sequence of elementary row operations. It is not difficult to prove that if A and B are row-equivalent augmented matrices of two systems of linear equations. then the two systems have the same solution sets
Gaussian elimination Gaussian elimination performs row operations on the augmented matrix until the portion corresponding to the coefficient matrix is reduced to upper-triangular form. In upper-triangular form, a simple procedure known as back substitution determines the solution. EX.2
Systematic solution if we perform elementary row operations on the augmented matrix of the system and get a matrix with one of its rows equal to [0 0 0... 0 b], where b 0, or a row of the form [0 0 0... 0], then the system is said to be inconsistent. In this situation, there may be no solution or infinitely many solutions.
Computing The Inverse The matrix is singular if during back substitution you obtain a row of zeros in the coefficient matrix.
Homogeneous systems is always consistent since x 1 = 0,...,x n = 0 is a solution. This solution is called the trivial solution, and any other solution is called a nontrivial solution. To solve a system of the form Ax = 0, there is no reason to form the augmented matrix, since all components will remain zero during row elimination. After reduction to uppertriangular form, if the element in position(n, n)is nonzero, the system has the unique solution x = 0; otherwise, there is an infinite number of solutions, and the matrix A is singular.
Application: A Trus A truss is a structure normally containing triangular units constructed of straight members with ends connected at joints referred to as pins. Trusses are the primary structural component of many bridges. External forces and reactions to those forces are considered to act only at the pins and result in internal forces in the members, which are either tensile or compressive.
Matrix Factorization In algebra, the polynomial x 2 5x + 6 can be factored as (x 3)(x 2). Under the right conditions, a matrix can also be factored. matrix factorization, a topic of great importance in numerical linear algebra. A bidiagonal matrix is a matrix with nonzero entries along the main diagonal and either the diagonal above or the diagonal below. The matrix B1 is an upper bidiagonal matrix and B2 is a lower bidiagonal matrix. A tridiagonal matrix has only nonzero entries along the main diagonal and the diagonals above and below. T is a tridiagonal matrix
Matrix Factorization Using the MATLAB command diag, build the tridiagonal matrix T :
Positive Definite If A is an n n matrix, and vector x is an n 1 column vector, then x T is a 1 n row vector. Consider the product x T Ax. The product is of dimension (1 n) (n n) (n 1) = 1 1, or a scalar. A symmetric matrix with the property that x T Ax > 0 for all x 0 is said to be positive definite. Positive definite matrices play a role in many fields of engineering and science. We will study these matrices later in this course. A positive definite matrix can be uniquely factored into the product R T R, where R is an uppertriangular matrix. The MATLAB command gallery produces many different kinds of matrices to use for testing purposes. It generates a 5 5 positive-definite matrix. The command chol(a) computes the matrix R. Use it to find the factorization R T R of A.
Matlab - display MATLAB automatically generates a display is not displayed if a semicolon is typed at the end The disp Command Only one variable can be displayed in a disp command. If elements of two variables need to be displayed together, a new variable (that contains the elements to be displayed) must first be defined and then displayed.
Output Commands The fprintf Command The fprintf command can be used to display output (text and data) on the screen or to save it to a file. With this command (unlike with the disp command) the output can be formatted. Using the fprintf command to display text: example It is possible to start a new line in the middle of the string When a program has more than one fprintf command, the display generated is continuous! \b Backspace. \t Horizontal tab
Output Commands Using the fprintf command to display a mix of text and numerical data. The first number (5 in the example) is the field width the second number (2 in the example) is the precision The display generated by the fprintf command combines text and a number.
Output Commands With the fprintf command it is possible to insert more than one number (value of a variable) within the text. Print theta, v and d using fprintf(?)
Output Commands The fprintf command is vectorized. This means that when a variable that is a vector or a matrix is included in the command, the command repeats itself until all the elements are displayed. If the variable is a matrix, the data is used column by column.
Output Commands Using the fprintf command to save output to a file In addition to displaying output in the Command Window, the fprintf command can be used for writing the output to a file when it is necessary to save the output. Writing output to a file requires three steps: a) Opening a file using the fopen command. b) Writing the output to the open file using the fprintf command. c) Closing the file using the fclose command.
Output Commands Step a: Step b: Step c: