+ All Categories
Home > Documents > Applied Linear Algebra in Geoscience Using MATLABshahraki/index_htm_files/LA_Matlab-Lecture4.pdf ·...

Applied Linear Algebra in Geoscience Using MATLABshahraki/index_htm_files/LA_Matlab-Lecture4.pdf ·...

Date post: 29-Aug-2019
Category:
Upload: doantu
View: 217 times
Download: 0 times
Share this document with a friend
21
Applied Linear Algebra in Geoscience Using MATLAB (Linear equations) Applied Linear Algebra in Geoscience Using MATLAB
Transcript
Page 1: Applied Linear Algebra in Geoscience Using MATLABshahraki/index_htm_files/LA_Matlab-Lecture4.pdf · In algebra, the polynomial x2 5x + 6 can be factored as (x 3)(x 2). Under the right

Applied Linear Algebra in Geoscience Using MATLAB

(Linear equations)

Applied Linear Algebra in Geoscience Using MATLAB

Page 2: Applied Linear Algebra in Geoscience Using MATLABshahraki/index_htm_files/LA_Matlab-Lecture4.pdf · In algebra, the polynomial x2 5x + 6 can be factored as (x 3)(x 2). Under the right

Contents

Applied Linear Algebra in Geoscience Using MATLAB

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

Page 3: Applied Linear Algebra in Geoscience Using MATLABshahraki/index_htm_files/LA_Matlab-Lecture4.pdf · In algebra, the polynomial x2 5x + 6 can be factored as (x 3)(x 2). Under the right

Recap

EX.1

Applied Linear Algebra in Geoscience Using MATLAB

The system of three equations with three unknowns

Page 4: Applied Linear Algebra in Geoscience Using MATLABshahraki/index_htm_files/LA_Matlab-Lecture4.pdf · In algebra, the polynomial x2 5x + 6 can be factored as (x 3)(x 2). Under the right

Introduction to Linear Equation

Applied Linear Algebra in Geoscience Using MATLAB

A system of n linear equations in n unknowns x1, x2, . . . , xn 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 x1, x2, . . . ,xn that satisfy each of the equations simultaneously. We say that the system is consistent if it has asolution. Otherwise, the system is called inconsistent.

Geometrically, solving a system of linear equations in two (or three) unknowns is equivalent todetermining whether or not a family of lines (or planes) has a common point of intersection.

coefficient matrix augmented matrix upper triangular

Page 5: Applied Linear Algebra in Geoscience Using MATLABshahraki/index_htm_files/LA_Matlab-Lecture4.pdf · In algebra, the polynomial x2 5x + 6 can be factored as (x 3)(x 2). Under the right

Introduction to Linear Equation

Applied Linear Algebra in Geoscience Using MATLAB

Find a polynomial of degree three, which passes through the points:( 3, 2), ( 1, 2), (1, 5), (2, 1)

AX = b

Page 6: Applied Linear Algebra in Geoscience Using MATLABshahraki/index_htm_files/LA_Matlab-Lecture4.pdf · In algebra, the polynomial x2 5x + 6 can be factored as (x 3)(x 2). Under the right

Row equivalence

Applied Linear Algebra in Geoscience Using MATLAB

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

Page 7: Applied Linear Algebra in Geoscience Using MATLABshahraki/index_htm_files/LA_Matlab-Lecture4.pdf · In algebra, the polynomial x2 5x + 6 can be factored as (x 3)(x 2). Under the right

Gaussian elimination

Applied Linear Algebra in Geoscience Using MATLAB

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

Page 8: Applied Linear Algebra in Geoscience Using MATLABshahraki/index_htm_files/LA_Matlab-Lecture4.pdf · In algebra, the polynomial x2 5x + 6 can be factored as (x 3)(x 2). Under the right

Systematic solution

Applied Linear Algebra in Geoscience Using MATLAB

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.

Page 9: Applied Linear Algebra in Geoscience Using MATLABshahraki/index_htm_files/LA_Matlab-Lecture4.pdf · In algebra, the polynomial x2 5x + 6 can be factored as (x 3)(x 2). Under the right

Computing The Inverse

Applied Linear Algebra in Geoscience Using MATLAB

The matrix is singular if during back substitution you obtain a row of zeros in the coefficient matrix.

Page 10: Applied Linear Algebra in Geoscience Using MATLABshahraki/index_htm_files/LA_Matlab-Lecture4.pdf · In algebra, the polynomial x2 5x + 6 can be factored as (x 3)(x 2). Under the right

Homogeneous systems

Applied Linear Algebra in Geoscience Using MATLAB

is always consistent since x1= 0, . . . ,xn = 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 upper-triangular form, if the element in position(n, n)is nonzero, the system has the uniquesolution x = 0; otherwise, there is an infinite number of solutions, and the matrix A issingular.

Page 11: Applied Linear Algebra in Geoscience Using MATLABshahraki/index_htm_files/LA_Matlab-Lecture4.pdf · In algebra, the polynomial x2 5x + 6 can be factored as (x 3)(x 2). Under the right

Application: A Trus

Applied Linear Algebra in Geoscience Using MATLAB

A truss is a structure normally containing triangular units constructed of straight memberswith ends connected at joints referred to as pins. Trusses are the primary structuralcomponent of many bridges. External forces and reactions to those forces are considered toact only at the pins and result in internal forces in the members, which are either tensile orcompressive.

Page 12: Applied Linear Algebra in Geoscience Using MATLABshahraki/index_htm_files/LA_Matlab-Lecture4.pdf · In algebra, the polynomial x2 5x + 6 can be factored as (x 3)(x 2). Under the right

Matrix Factorization

Applied Linear Algebra in Geoscience Using MATLAB

In algebra, the polynomial x2 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

Page 13: Applied Linear Algebra in Geoscience Using MATLABshahraki/index_htm_files/LA_Matlab-Lecture4.pdf · In algebra, the polynomial x2 5x + 6 can be factored as (x 3)(x 2). Under the right

Matrix Factorization

Applied Linear Algebra in Geoscience Using MATLAB

Using the MATLAB command diag, build the tridiagonal matrix T :

Page 14: Applied Linear Algebra in Geoscience Using MATLABshahraki/index_htm_files/LA_Matlab-Lecture4.pdf · In algebra, the polynomial x2 5x + 6 can be factored as (x 3)(x 2). Under the right

Positive Definite

Applied Linear Algebra in Geoscience Using MATLAB

If A is an n × n matrix, and vector x is an n × 1 column vector, then xT is a 1 × n row vector.Consider the product xTAx.

The product is of dimension (1 × n) (n × n) (n × 1) = 1 × 1, or a scalar. A symmetric matrix with the property that xTAx > 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 RTR, where R is an upper-triangular 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 RTR of A.

Page 15: Applied Linear Algebra in Geoscience Using MATLABshahraki/index_htm_files/LA_Matlab-Lecture4.pdf · In algebra, the polynomial x2 5x + 6 can be factored as (x 3)(x 2). Under the right

Matlab - display

Applied Linear Algebra in Geoscience Using MATLAB

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 adisp command. If elements of two

variables need to be displayed together,a new variable (that contains theelements to be displayed) must first bedefined and then displayed.

Page 16: Applied Linear Algebra in Geoscience Using MATLABshahraki/index_htm_files/LA_Matlab-Lecture4.pdf · In algebra, the polynomial x2 5x + 6 can be factored as (x 3)(x 2). Under the right

Output Commands

Applied Linear Algebra in Geoscience Using MATLAB

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:

It is possible to start a new line in the middle of the string

example

When a program has more than one fprintf command,

the display generated is continuous !

\b Backspace.\t Horizontal tab

Page 17: Applied Linear Algebra in Geoscience Using MATLABshahraki/index_htm_files/LA_Matlab-Lecture4.pdf · In algebra, the polynomial x2 5x + 6 can be factored as (x 3)(x 2). Under the right

Output Commands

Applied Linear Algebra in Geoscience Using MATLAB

Using the fprintf command to display a mix of text and numerical data.

The first number (5 in the example) is the field widththe second number (2 in the example) is the precision

The display generated by the fprintf command combines text and a number.

Page 18: Applied Linear Algebra in Geoscience Using MATLABshahraki/index_htm_files/LA_Matlab-Lecture4.pdf · In algebra, the polynomial x2 5x + 6 can be factored as (x 3)(x 2). Under the right

Output Commands

Applied Linear Algebra in Geoscience Using MATLAB

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(?)

Page 19: Applied Linear Algebra in Geoscience Using MATLABshahraki/index_htm_files/LA_Matlab-Lecture4.pdf · In algebra, the polynomial x2 5x + 6 can be factored as (x 3)(x 2). Under the right

Output Commands

Applied Linear Algebra in Geoscience Using MATLAB

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 aredisplayed. If the variable is a matrix, the data is used column by column.

Page 20: Applied Linear Algebra in Geoscience Using MATLABshahraki/index_htm_files/LA_Matlab-Lecture4.pdf · In algebra, the polynomial x2 5x + 6 can be factored as (x 3)(x 2). Under the right

Output Commands

Applied Linear Algebra in Geoscience Using MATLAB

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.

Page 21: Applied Linear Algebra in Geoscience Using MATLABshahraki/index_htm_files/LA_Matlab-Lecture4.pdf · In algebra, the polynomial x2 5x + 6 can be factored as (x 3)(x 2). Under the right

Output Commands

Applied Linear Algebra in Geoscience Using MATLAB

Step c:

Step b:

Step a:


Recommended