Applied Linear Algebra in Geoscience Using MATLAB

Similar documents
(Mathematical Operations with Arrays) Applied Linear Algebra in Geoscience Using MATLAB

Applied Linear Algebra in Geoscience Using MATLAB

(Linear equations) Applied Linear Algebra in Geoscience Using MATLAB

Applied Linear Algebra in Geoscience Using MATLAB

Linear Algebra Section 2.6 : LU Decomposition Section 2.7 : Permutations and transposes Wednesday, February 13th Math 301 Week #4

There are six more problems on the next two pages

Numerical Linear Algebra

Matrix decompositions

Linear Algebra Linear Algebra : Matrix decompositions Monday, February 11th Math 365 Week #4

Matrix decompositions

Linear Systems of n equations for n unknowns

Solution of Linear Equations

Matrix decompositions

Conceptual Questions for Review

LECTURE NOTES ELEMENTARY NUMERICAL METHODS. Eusebius Doedel

Gaussian Elimination and Back Substitution

MATH 3511 Lecture 1. Solving Linear Systems 1

Numerical Linear Algebra

CS227-Scientific Computing. Lecture 4: A Crash Course in Linear Algebra

1 Number Systems and Errors 1

ANSWERS. E k E 2 E 1 A = B

Review of matrices. Let m, n IN. A rectangle of numbers written like A =

Scientific Computing

Direct Methods for Solving Linear Systems. Simon Fraser University Surrey Campus MACM 316 Spring 2005 Instructor: Ha Le

Numerical Methods - Numerical Linear Algebra

Cheat Sheet for MATH461

The Solution of Linear Systems AX = B

This can be accomplished by left matrix multiplication as follows: I

MAC1105-College Algebra. Chapter 5-Systems of Equations & Matrices

Solving Linear Systems of Equations

The value of a problem is not so much coming up with the answer as in the ideas and attempted ideas it forces on the would be solver I.N.

CME 302: NUMERICAL LINEAR ALGEBRA FALL 2005/06 LECTURE 6

CPE 310: Numerical Analysis for Engineers

Math 102, Winter Final Exam Review. Chapter 1. Matrices and Gaussian Elimination

Linear Algebra March 16, 2019

MTH5112 Linear Algebra I MTH5212 Applied Linear Algebra (2017/2018)

L2-7 Some very stylish matrix decompositions for solving Ax = b 10 Oct 2015

Laboratory #3: Linear Algebra. Contents. Grace Yung

Numerical Methods for Engineers. and Scientists. Applications using MATLAB. An Introduction with. Vish- Subramaniam. Third Edition. Amos Gilat.

MODEL ANSWERS TO THE FIRST QUIZ. 1. (18pts) (i) Give the definition of a m n matrix. A m n matrix with entries in a field F is a function

CHAPTER 6. Direct Methods for Solving Linear Systems

MATRICES. a m,1 a m,n A =

Math 520 Exam 2 Topic Outline Sections 1 3 (Xiao/Dumas/Liaw) Spring 2008

2.1 Gaussian Elimination

lecture 2 and 3: algorithms for linear algebra

MATH 1120 (LINEAR ALGEBRA 1), FINAL EXAM FALL 2011 SOLUTIONS TO PRACTICE VERSION

Next topics: Solving systems of linear equations

Matrix Factorization Reading: Lay 2.5

Linear Algebra, part 3 QR and SVD

1 9/5 Matrices, vectors, and their applications

MAT 343 Laboratory 3 The LU factorization

GAUSSIAN ELIMINATION AND LU DECOMPOSITION (SUPPLEMENT FOR MA511)

Applied Linear Algebra

Example Linear Algebra Competency Test

Linear Equations in Linear Algebra

MAT Linear Algebra Collection of sample exams

Review Questions REVIEW QUESTIONS 71

Gaussian Elimination without/with Pivoting and Cholesky Decomposition

TMA4125 Matematikk 4N Spring 2017

Preliminary Examination, Numerical Analysis, August 2016

Solving linear equations with Gaussian Elimination (I)

Introduction to Applied Linear Algebra with MATLAB

MATH 2030: ASSIGNMENT 4 SOLUTIONS

Math 344 Lecture # Linear Systems

A Brief Outline of Math 355

Fundamentals of Engineering Analysis (650163)

MATH 240 Spring, Chapter 1: Linear Equations and Matrices

Chapter 4. Solving Systems of Equations. Chapter 4

homogeneous 71 hyperplane 10 hyperplane 34 hyperplane 69 identity map 171 identity map 186 identity map 206 identity matrix 110 identity matrix 45

1 Multiply Eq. E i by λ 0: (λe i ) (E i ) 2 Multiply Eq. E j by λ and add to Eq. E i : (E i + λe j ) (E i )

Glossary of Linear Algebra Terms. Prepared by Vince Zaccone For Campus Learning Assistance Services at UCSB

Applied Linear Algebra

Linear Algebra review Powers of a diagonalizable matrix Spectral decomposition

Linear Algebra Practice Problems

NUMERICAL METHODS USING MATLAB

Linear Algebra review Powers of a diagonalizable matrix Spectral decomposition

IMPORTANT DEFINITIONS AND THEOREMS REFERENCE SHEET

Lecture 1 Systems of Linear Equations and Matrices

Relationships Between Planes

Introduction to Matrices

Contents. 1 Vectors, Lines and Planes 1. 2 Gaussian Elimination Matrices Vector Spaces and Subspaces 124

MATHEMATICS FOR COMPUTER VISION WEEK 2 LINEAR SYSTEMS. Dr Fabio Cuzzolin MSc in Computer Vision Oxford Brookes University Year

Math 4A Notes. Written by Victoria Kala Last updated June 11, 2017

MATH 315 Linear Algebra Homework #1 Assigned: August 20, 2018

IMPORTANT DEFINITIONS AND THEOREMS REFERENCE SHEET

lecture 3 and 4: algorithms for linear algebra

3 QR factorization revisited

4 Elementary matrices, continued

MATH 310, REVIEW SHEET 2

Linear Algebra Primer

Numerical Analysis Preliminary Exam 10 am to 1 pm, August 20, 2018

Pivoting. Reading: GV96 Section 3.4, Stew98 Chapter 3: 1.3

Numerical Linear Algebra

Program Lecture 2. Numerical Linear Algebra. Gaussian elimination (2) Gaussian elimination. Decompositions, numerical aspects

Linear Algebraic Equations

Table 1 Principle Matlab operators and functions Name Description Page reference

Linear Equations in Linear Algebra

POLI270 - Linear Algebra

Main matrix factorizations

1 GSW Sets of Systems

Transcription:

Applied Linear Algebra in Geoscience Using MATLAB

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 Linear Independence Basis of a Subspace The Rank of a Matrix Implementing the QR factorization The algebraic eigenvalue problem

Norm L1, L2 and inf It is helpful to view the unit sphere of a norm, the unit spheres for the -, 1-, and 2-norm have equations

LU Decomposition We practiced the process of solving a non-singular linear system Ax = b using Gaussian elimination. We formed the augmented matrix A b and applied the elementary row operations as below, to reduce A to upper-triangular form. 1. Multiplying a row by a scalar. 2. Subtracting a multiple of one row from another 3. Exchanging two rows Following this step, back substitution computed the solution. In many applications where linear systems appear, one needs to solve Ax = b for many different vectors b. Most of the work in Gaussian elimination is applying row operations to arrive at the uppertriangular matrix. If we need to solve several different systems with the same A, then we would like to avoid repeating the steps of Gaussian elimination on A for every different b. This can be accomplished by the LU decomposition, which in effect records the steps of Gaussian elimination. Since Gaussian elimination is used so often, the algorithm must be stable. Unfortunately, this is not true, and we must add an operation termed partial pivoting.

LU Decomposition The first step of Gaussian elimination is to use a 11 = 1 as the pivot and subtract 2 times the first row from the second and 3 times the first row from the third Record these actions by placing the multipliers 2 and 3 into the entries they made zero. In order to make it clear that we are recording multipliers and not elements of A, put the entries in parentheses. This leads to: Thus, we see that A is the product of the lower triangular L and the upper triangular U. When a matrix can be written as a product of simpler matrices, we call that a decomposition and this one we call the LU decomposition.

Using LU To Solve Equations Factor A into the product of L and U: First solve Ly = b. This finds y = Ux. Now solve Ux = y to find x. Each of these solution steps is simple. First, the system Ly is lower triangular. Next, the system Ux = y is upper triangular.

Using LU To Solve Equations

Using LU To Solve Equations

Gaussian Elimination With Partial Pivoting Gaussian elimination can produce extremely bad results under certain circumstances; in fact, the results can be completely wrong!!! Consider the matrix, and use three-digit arithmetic. There is only one step required to produce the LU decomposition. Use the multiplier 2/0.00001 The problem arose when we divided by a small pivot element and obtained a large multiplier. The large multiplier resulted in the addition of a very large number to a much smaller number. The result was loss of any contribution from the small number. In our three-digit arithmetic, the 1 is lost, and the result is Now compute LU to get which is disastrously different from A!

Using LU To Solve Equations There is a good solution to this problem. When choosing the pivot element on the diagonal at position aii, locate the element in column i at or below the diagonal that is largest in magnitude, say aji, i j n. If j i, interchange row j with row i, and then the multipliers, a ji /a ii, satisfy a ji /a ii 1, i + 1 j n, and we avoid multiplying a row by a large number and losing precision. We call this Gaussian elimination with partial pivoting (GEPP). Of course, this is not the original matrix A, but A with its two rows swapped (permuted). If we use GEPP, then an LU decomposition for A consists of three matrices P, L, and U such that

Using LU To Solve Equations P is a permutation matrix, also called the pivot matrix. Start with P = I, and swap rows i and j of the permutation matrix whenever rows i and j are swapped during GEPP. For instance, would be the permutation matrix if the second and third rows of A are interchanged during pivoting. Pivot row = 1. Swap rows 1 and 3, and permute P. Do not interchange rows of L until arriving at the pivot in row 2, column 2 Apply the pivot element, and add multipliers to L. Pivot row = 2. Swap rows 2 and 3. Permute P and L.

Using LU To Solve Equations Apply the pivot element and update L. The final results are NOTE: Even if a row interchange occurs when dealing with column 1, do not interchange the corresponding rows of L until moving to column 2. Think of it this way. The matrix A after a row swap defines the starting configuration. The elements in the first column of L correspond to the multipliers after the row interchange involving pivot position (1, 1),if any.

A good reason for computing L and U is that the cubic LU decomposition algorithm allows us to repeatedly solve Ax = b for many b s without having to re-compute either L or U

Eq. with One Variable Numerical methods are commonly used for solving mathematical problems that are formulated in science (and engineering) where it is difficult or impossible to obtain exact solutions A solution to the equation (also called a root) is a numerical value of x that satisfies the equation (graphically, crosses or touches the x axis) If such a value does not exist or is difficult to determine, a numerical solution can be determined by finding an x that is very close to the solution. This is done by the iterative process, where in each iteration we determine a value of x that is closer to the solution.

Eq. with One Variable NOTE: The function has to be written in a standard form. EX) Determine the solution of the above equation Lets to plot this fun. first

Max or Min of a Function The fzero command finds zeros of a function only where the function crosses the x axis. The command does not find a zero at points where the function touches but does not cross the X axis. The fzero command can also be used to find the value of x where the function has a specific value. This is done by translating the function up or down 0.1 In many applications there is a need to determine the local minimum or maximum of a function In calculus the value of x that corresponds to a local minimum or maximum is determined by finding the zero of the derivative of the function. The value of y is determined by substituting the x into the function.

ODEs Ex) Local min Abs. min Notice that the fminbnd command gives the local minimum.

Numerical Integration The fminbnd command can also be used to find the maximum of a function. This is done by multiplying the function by 1 and finding the minimum. Calculating area and volume, velocity from acceleration, and work from force and displacement are just a few examples where integrals are used. In calculus courses the integrand (the quantity to be integrated) is usually a function. In applications of science and engineering the integrand can be a function or a set of data points. A definite integral In numerical integration the total area is obtained by dividing the area into small sections, calculating the area of each section, and adding Them up.

Numerical Integration Various numerical methods have been developed for this purpose. The difference between the methods is in the way that the area is divided into sections and the method by which the area of each section is calculated. In MATLAB The quad and quadl commands are used for integration when f(x) is a function, and trapz is used when f(x) is given by data points. The quad command, uses the adaptive Simpson method of integration. The quadl command uses the adaptive Lobatto method, which can be more efficient for high accuracies and smooth integrals. The function must be written for an argument x that is a vector (use element-by-element operations) such that it calculates the value of the function for each element of x.

ODEs make sure that the function does not have a vertical asymptote between a and b. Ex) Use numerical integration to calculate the following integral: The trapz command can be used for integrating a function that is given as data points. It uses the numerical trapezoidal method of integration where x and y are vectors with the x and y coordinates of the points, respectively. The two vectors must be of the same length.

ODEs Differential equations play a crucial role in science and engineering since they are in the foundation of virtually every physical phenomenon. However, only a limited number of differential equations can be solved analytically. Numerical methods, on the other hand, can result in an approximate solution to almost any equation. An ordinary differential equation (ODE) is an equation that contains an independent variable, a dependent variable, and derivatives of the dependent variable. x and y are the independent and dependent variables, respectively. A solution is a function y=f(x) that satisfies the equation. In general, many functions can satisfy a given ODE, and more information is required for determining the solution of a specific problem.

ODEs Step 1: Write the problem in a standard form. Step 2: Create a user-defined function (in a function file) or an anonymous function. The ODE to be solved has to be written as a user-defined function or as an anonymous function. Step 3: Select a method of solution. lists seven ODE solver commands, which are MATLAB built-in functions that can be used for solving a first order ODE. Step 4: Solve the ODE. A vector that specifies the interval of the solution. The vector must have at least two elements but can have more.

ODEs In general, the solvers can be divided into two groups according to their ability to solve stiff problems and according to whether they use on-step or multistep methods Stiff problems are ones that include fast and slowly changing components and require small time steps in their solution One-step solvers use information from one point to obtain a solution at the next point. Multistep solvers use information from several previous points to find the solution at the next point. It is impossible to know ahead of time which solver is the most appropriate for a specific problem. A suggestion is to first try ode45, which gives good results for many problems. If a solution is not obtained because the problem is stiff, trying the solver ode15s is suggested.

ODEs

Examples The ideal gas equation relates the volume (V in L), temperature (T in K), pressure (P in atm), and the amount of gas (number of moles n) by: where R = 0.08206 (L atm)/(mol K) is the gas constant. The van der Waals equation gives the relationship between these quantities for a real gas by where a and b are constants that are specific for each gas. Use the fzero function to calculate the volume of 2 mol CO2 at temperature of 50 C, and pressure of 6 atm.

ODEs In order for the script and function files to work correctly, the variables P, T, n, a, b, and R are declared global. To estimate the amount of water that flows in a river during a year, a section of the river is made to have a rectangular cross section as shown. In the beginning of every month (starting at January 1st) the height h of the water and the speed v of the water flow are measured. The first day of measurement is taken as 1, and the last day which is January 1st of the next year is day 366. The following data was measured:

ODEs Use the data to calculate the flow rate, and then integrate the flow rate to obtain an estimate of the total amount of water that flows in the river during a year. The flow rate, Q (volume of water per second), at each data point is obtained by multiplying the water speed by the width and height of the cross-sectional area of the water that flows in the channel: The total amount of water that flows is estimated by the integral: