Systems of Linear Equations on MATLAB-Machine Learning-Lecture Handout, Exercises for Machine Learning. Pakistan Institute of Engineering and Applied Sciences, Islamabad (PIEAS)

Machine Learning

Description: This lecture notes was distributed for Machine Learning course by Pakistan Institute of Engineering and Applied Sciences, Islamabad (PIEAS). Its main points are: Systems, Linear, Equations, MATLAB, Implementation, Residuals, Elementary, Elimination, Matrices, Gaussian
Showing pages  1  -  2  of  22
The preview of this document ends here! Please or to read the full document or to download it.
Document information
Uploaded by: zaraa
Views: 1000+
Downloads : 0
University: Pakistan Institute of Engineering and Applied Sciences, Islamabad (PIEAS)
Upload date: 19/07/2012
Embed this document:

Dr. Hanif Durad 2

Lecture Outline (1/2)  Calculating Small Residuals  Forward-substitution for lower triangular system

Lx = b  Back-substitution for upper triangular system

Ux = b  Elementary Elimination Matrices  Gaussian Elimination  Finding Permutation Matrix

Dr. Hanif Durad 3

Lecture Outline (2/2)  Gaussian Elimination with Partial Pivoting  Gaussian Jordan Elimination with Partial

Pivoting  Crout’s Decomposition  Cholesky’s Decomposition  Tridiagonal Decomposition

Example 2.8 :Calculating Small Residuals

A=[.913 .659;.457 .33] A =

0.9130 0.6590 0.4570 0.3300

>> b=[.254 .127]' b =

0.2540 0.1270

>> x=A\b x =

1.0000 -1.0000

>> r=A*x-b r = 1.0e-016 * 0 -0.5551

>>cond(A) ans = 1.2485e+004Refer EMSE, P-230

P-63

Forward-substitution for lower triangular system Lx = b

>> L L =

-1 0 0 -4 -6 0 1 2 2

>> b b =

1 -6 3

>> x=LTriSol(L,b) x =

-1.0000 1.6667 0.3333

Refer SCMV, P-198

P-65

Back-substitution for upper triangular system Ux = b

>> U U =

1 2 2 0 -4 -6 0 0 -1

>> b=[3 -6 1]' b =

3 -6 1

>> UTriSol(U,b) ans =

-1 3 -1

Refer SCMV, P-197

Example 2.11, P-66

Example 2.11: Elementary Elimination Matrices (1/2)

>> a=[2 4 -2]';k=1 k =

1 >> a=[2 4 -2]';k=1; >> m1=Gaussv (a,k) m1 =

0 2 -1

>> Gaussprod(m1,k,a) ans =

2 0 0

Tutorial 4, P-5

Example 2.12, P-67

Example 2.11: Elementary Elimination Matrices (2/2)

>> m2=Gaussv (a,k) m2 =

0 0

-0.5000 >> Gaussprod(m2,k,a) ans =

2 4 0

Gaussian Elimination (1/2)

>> A=[1 2 2;4 4 2;4 6 4]; >> b=[3 6 10]'; >> [L,U]=GE(A)

L = 1.0000 0 0 1.0000 1.0000 0 0.2500 0.5000 1.0000

U = 4.0000 4.0000 2.0000

0 2.0000 2.0000 0 0 0.5000

Refer SCMV, P-198 Example 2.16, P-73

Gaussian Elimination (2/2)

>> y=LTriSol(L,b) y =

3 -6 1

>> x=UTriSol(U,y) x =

-1 3 -1

Refer SCMV, P-198 Example 2.16, P-73

Another Example

Dr. Hanif Durad 11

Burden NA, P-345

b b’ Burden NA, P-391

Finding Permutation Matrix

>>[L, U, P] = lu(A) L =

1.0000 0 0 1.0000 1.0000 0 0.2500 0.5000 1.0000

U = 4.0000 4.0000 2.0000

0 2.0000 2.0000 0 0 0.5000

P =

0 1 0 0 0 1 1 0 0

Introduction_to_MATLAB.pdf, P-36/44 Example 2.16, P-73

Gaussian Elimination with Partial Pivoting

>> A=[1 2 2;4 4 2;4 6 4]; >> b=[3 6 10]'; >> [L,U]=GEpiv(A)

L = 1.0000 0 0 4.0000 1.0000 0 4.0000 0.5000 1.0000

U = 1 2 2 0 -4 -6 0 0 -1

Refer SCMV, P-198

Example 2.12, P-67

Gaussian Jordan Elimination with Partial Pivoting

>> A=[1 2 2;4 4 2;4 6 4]; b=[3 6 10]'; >> ab=[A b] ab =

1 2 2 3 4 4 2 6 4 6 4 10

>> [C,t]=GJE(ab) C =

1 0 0 -1 0 1 0 3 0 0 1 -1

t = 3.4201e-004

http://www.mathworks.com/matlabcentral/fx_files/10318/1/elimgauss03.m

new time commands tic & toc

MATLAB Verification

D=rref(ab)

D =

1 0 0 -1 0 1 0 3 0 0 1 -1

MPA, P-347

Using Gaussian Jordan Elimination to find Matrix inverse

 What do you suggest?

>> A=[1 2 2;4 4 2;4 6]; >> b=eye(3,3); >> Ab=[A b]; >> C=GJE(Ab) C =

1.0000 0 0 1.0000 1.0000 -1.0000 0 1.0000 0 -2.0000 -1.0000 1.5000 0 0 1.0000 2.0000 0.5000 -1.0000

Example 2.18, P-81

LU Decomposition

 Doolittle’s method ( Discussed in previous examples)  Crout’s reduction (U has ones on the diagonal)  Cholesky’s method

CVEN 302\lecture13.ppt p-5/23

Crout’s Decomposition >> A=[2 -1 0 0;-1 2 -1 0;0 -1 2 -1;0 0 -1 2] >> [L,U] = LU_crout_factor(A) L =

2.0000 0 0 0 -1.0000 1.5000 0 0

0 -1.0000 1.3333 0 0 0 -1.0000 1.2500

U =

1.0000 -0.5000 0 0 0 1.0000 -0.6667 0 0 0 1.0000 -0.7500 0 0 0 1.0000

Burden NA, Example 5, P-409

Cholesky’s Decomposition >> A=[3 -1 -1; -1 3 -1;-1 -1 3] A =

3 -1 -1 -1 3 -1 -1 -1 3

>> Cholesky(A) ans =

1.7321 -0.5774 -0.5774 0 1.6330 -0.8165 0 0 1.4142

>> L=ans‘ L =

1.7321 0 0 -0.5774 1.6330 0 -0.5774 -0.8165 1.4142

Dr. Hanif Durad 19

Example 2.21, P-86

MATLAB Cholesky’s Decomposition

U = chol(A) produces an upper triangular matrix U from the diagonal and upper triangle of matrix A, satisfying the equation U'*U=A

U = chol(A) U =

1.7321 -0.5774 -0.5774 0 1.6330 -0.8165 0 0 1.4142

Dr. Hanif Durad 20

Tridiagonal Decomposition >> A=[2.04 -1 0 0; -1 2.04 -1 0;0

-1 2.04 -1;0 0 -1 2.04]; [L,U,p] = lutx(A) L =

1.0000 0 0 0 -0.4902 1.0000 0 0

0 -0.6452 1.0000 0 0 0 -0.7170 1.0000

U = 2.0400 -1.0000 0 0

0 1.5498 -1.0000 0 0 0 1.3948 -1.0000 0 0 0 1.3230

p = 1 2 3 4

Dr. Hanif Durad 21

Example 2.21, P-86

Chapra NME, P-263

Tridiagonal System Solution (1/2)  The example has been taken from Chapra’s

book

Dr. Hanif Durad 22

Example11.1, P-286

Tridiagonal System Solution (2/2)

A=[2.04 -1 0 0; -1 2.04 -1 0;0 -1 2.04 -1;0 0 -1 2.04] e=[0 -1 -1 -1]' f=[2.04 2.04 2.04 2.04 ]' g=[-1 -1 -1 0]' r=[40.8 .8 .8 200.8]‘ x = Tridiag(e,f,g,r) x =

65.9698 93.7785 124.5382 159.4795

Dr. Hanif Durad 23

Docsity is not optimized for the browser you're using. In order to have a better experience please switch to Google Chrome, Firefox, Internet Explorer 9+ or Safari! Download Google Chrome