persamaan linier - eliminasi gauss

of 58 /58
Bab 4 Bab 4 Persamaan Linier Persamaan Linier Eliminasi Gauss Eliminasi Gauss

Author: miftnidzo

Post on 04-Apr-2015

713 views

Category:

Documents


9 download

Embed Size (px)

TRANSCRIPT

Bab 4

Persamaan Linier Eliminasi Gauss

Matrik sederhanaa 11 x1 x a 21 1 / n 1 x1 a a12 x 2 a 22 x 2 an 2 x2 . . . a1 n x n a2 n xn a nn x n ! b1 ! b2 / ! bn

Untuk persamaan linier yang sederhana, maka metode :

Graphical Cramer's rule Elimination

Graphical Method2 x1 x 2 3 x rearra ge 2 x x 3 x 1 2 2 2 x1 3 3 x1

x1 + x2 = 3

2x1 x2 = 3

One solution

Graphical MethodNo solution

2x1 x2 = 1 2x1 x2 = 3

Graphical MethodInfinite many solution

2x1 x2 = 3

6x1 3x2 = 9

Graphical MethodIll conditioned

2x1 x2 = 3

2.1x1 x2 = 3

Cramers RuleCara menghitung determinan D 2 x 2 matrix a11 a12 D! ! a11 a 22 a 12 a 21 a 21 a 22 3 x 3 matrixa11 D ! a 21 a 31 a12 a 22 a 32 a 22 a 32 a13 a 23 a 33 a 23 a 33

! a11

a12

a 21 a 31

a 23 a 33

a13

a 21 a 31

a 22 a 32

Cramers RuleTo find xk for the following system

a11 x1 a12 x 2 ... a1 n x n ! b1 a 21 x1 a 22 x 2 ... a 2 n x n ! b2 / a n 1 x1 a n 2 x 2 ... a nn x n ! bnReplace kth column of ads with bds (i.e., aik n bi ) ( ew matrix )

xk !

(a ij )

Example3 x 3 matrixx1 !1

b1 1 ! b2 b3 a11 a 21 a 31 a11 a 21 a 31

a12 a 22 a 32 b1 b2 b3 a12 a 22 a 32

a13 a 23 a 33 a13 a 23 a 33 b1 b2 b3

a 11 D ! a 21 a 31

a12 a 22 a 32

a13 a 23 a 33x3 !3

x2 !

2

!

1

!

1

IllIll-Conditioned SystemWhat happen if the determinant D is very small or zero?

D ! det ?AA} 0Divided by zero (linearly dependent system) Divided by a small number: Round-off error Loss of significant digits

Elimination Methoda 11 x 1 a12 x 2 ! b1 a 21 x1 a 22 x 2 ! b2 a 22 a11 x 1 a 22 a12 x 2 ! a 22 b1 Eliminate x2 a 12 a 21 x 1 a12 a 22 x 2 ! a 12 b2

Subtract to get

a 22 a 11 x 1 a 12 a 21 x1 ! a 22 b1 a12 b2

a11 b2 a 21 b1 a 22 b1 a12 b2 x1 ! x2 ! a 11 a 22 a 12 a 21 a 22 a11 a 12 a 21Not very practical for large number (> 4) of equations

Gauss EliminationManipulate equations to eliminate one of the unknowns Develop algorithm to do this repeatedly The goal is to set up upper triangular matrix

a11 a12 a13 . a 22 a 23 . U! a 33 . 1 Back substitution to find solution (root)

a1n a2 n a3n / a nn

Basic Gauss EliminationDirect Method (no iteration required) Forward elimination Column-by-column elimination of the below-diagonal elements Reduce to upper triangular matrix Back-substitution

Naive Gauss EliminationBegin with a11 x1 a12 x 2 ... a1 n x n ! b1a 21 x1 a 22 x 2 ... a 2 n x n ! b2 / a n 1 x1 a n 2 x 2 ... a nn x n ! bn Multiply the first equation by a21 / a11 and subtract a 11 x 1 a 12 x 2 ... a n x n ! b1 from second equation a a a a a 21 21 a11 x1 a 22 21 a12 x 2 ... a 2 n 21 a1 n x n ! b2 21 b1 a11 a11 a11 a11 / an 1 x1 a n 2 x 2 ... a nn x n ! bn

Gauss EliminationReduce toa11 x 1 a12 x 2 ... a1 n x n ! b1 d a d 2 ... a dx n ! b2 22 x 2n / a n 1 x1 a n 2 x 2 ... a nn x n ! bn

Repeat the forward elimination to geta11 x1 a12 x 2 ... a1 n x n ! b1 d a d 2 ... a dx n ! b2 22 x 2n / d d a n 2 x 2 ... a d n ! bn nn x

Gauss EliminationFirst equation is pivot equation a11 is pivot element Now multiply second equation by a'32 /a'22 and subtract from third equationa11 x1 a12 x 2 a13 x 3 - a1n x n ! b1 d ad 2 ad 3 - a dx n ! b2 22 x 23 x 2n

ad ad ad 32 32 ad d d a d x 3 - ad ad x n ! b3 32 b2 33 23 3n 2n ad ad ad 22 22 22 /

Gauss EliminationRepeat the elimination of adi2 and geta 11 x 1 a 12 x 2 a13 x 3 - a1 n x n ! b1 d a d 2 a d 3 - a dx n ! b2 22 x 23 x 2n d d d a d 3 - a dx n ! b3d 33 x 3n / dx d d a nd 3 - a d n ! bnd 3 nn x

Continue and get a11 x1 a12 x 2 a13 x 3 - a1n x n ! b1d d d d a22 x 2 a23 x 3 - a2 n x n ! b2 d d d d a33 x 3 - a3d n ! b3d nx /(n ( ann 1) x n ! bnn 1)

Back SubstitutionNow we can perform back substitution to get {x} By simple division ( n 1 )

bn x n ! ( n 1 ) ann( n 2 ) n 1, n

Substitute this into (n-1)th equation

a

( n 2 ) n 1, n 1

x n 1 a

xn ! b

( n 2 ) n 1

Solve for xn-1 Repeat the process to solve for xn-2 , xn-3 , . x2, x1

Back SubstitutionBack substitution: starting with xn Solve for xn1 , xn2 , , 3, 2, 1( bnn 1) x n ! ( n 1 ) ann

b xi !

( i1) i

a

j!i1 ( i 1) ii

a

n

( i 1) ij

xjfor i = n1, n2, , 1

a

( i 1) ii

{0

Naive Gauss Elimination

Elimination of first column a11 a 21 a31 a41 a11 0 0 0a12 a22 a32 a42 a13 a23 a33 a43 a14 a24 a34 a44 b1 b2 b3 b4 f 21 ! a21 / a11 f 31 ! a31 / a11 f 41 ! a41 / a11 ( 2 ) f 21 v ( 1) ( 3 ) f 31 v ( 1) ( 4 ) f 41 v ( 1)

a12 a13 a14 b1 d d d d a22 a23 a24 b2 d d d d a32 a33 a34 b3 d d d d a42 a43 a44 b4

Elimination of second column a11 0 0 0a12 a13 a14 b1 d a23 a24 b2 d d d a22 d d d d a32 a33 a34 b3 d d d d a42 a43 a44 b4 a11 a12 a13 a14 b1 0 ad ad ad bd 22 23 24 2 d d d d d 0 0 a33 a34 b3d d d d d d 0 a43 a44 b4d 0

d d f 32 ! a32 / a22 d d f 42 ! a42 / a22

( 3 ) f 32 v ( 2 ) ( 4 ) f 42 v ( 2 )

Elimination of third columna11 0 0 0 a11 0 0 0 a12 a13 a14 b1 d d d d a22 a23 a24 b2 d d d d d 0 a33 a34 a3d d d d d d 0 a43 a44 a4d a12 a13 a14 b1 d d d d a22 a23 a24 b2 d d d d d 0 a33 a34 b3d d d d d d 0 0 a44 b4d

d d d d f 43 ! a43 / a33Upper triangular matrix

( 4 ) f 43 v ( 3 )

BackBack-Substitutiona 11 a 12 a 13 0 ad ad 22 23 0 d 0 ad 33 0 0 0a 14 b1 d a d b2 24 d d a d b3d 34 d d d d a d b4d 44 Upper triangular matrix

d 44 d d x 4 ! b4d a d / d d 44 d d a 11 , a d, a d, a d{ 0 22 33 d 34 x d d x 3 ! ( b3d a d 4 ) / a d 33 d 23 x x 2 ! ( b2 a d 3 a d 4 ) / a d 24 x 22x 1 ! ( b1 a 12 x 2 a 13 x 3 a 14 x 4 ) / a 11

Example3 1 1 0 2 1 2 2 3 1 f 21 ! 1 0 1 1 f 31 ! 0 4 2 f 41 ! 6 4 1 6 2 2 2 3 1 1 0 ( 2 ) ( 1) v f 0 2 4 0 0 21 0 1 1 4 2 ( 3 ) ( 1) v f 31 0 2 10 14 5 ( 4 ) ( 1) v f 41

For ard Elimination1 0 0 0 1 0 0 0 0 2 1 0 2 0 2 4 1 2 4 1 3 0 4 3 0 4 14 1 0 2 5 1 0 2 5

f 32 ! 1/2 f 42 ! 1

2 10 14

( 3 ) ( 2 ) v f 32 ( 4 ) ( 2 ) v f 42

0 14

Upper Triangular Matrix1 0 0 0 1 0 0 0 0 2 1 0 2 0 2 4 1 2 4 3 0 4 3 0 4 14 1 0 2 5 1 0 2 33

2 14

f 43 ! 14

0 1

0 70

( 4 ) ( 3 ) v f 43

BackBack-Substitution1 0 0 0 0 1 2 4 0 0 0 1 4 2 0 0 70 33 2 3 13/70 8/35 T x! 4/35 33/70

x 4 ! 33/ 70 ! 33/70 x 3 ! 4 x 4 2 ! 4/35 x 2 ! 2 x 3 ! 8/35 x 1 ! 1 2 x 3 3 x 4 ! 13/70

MATLAB Script File: GaussNaive

>> format short >> x = GaussNaive(A,b) m = 4 n = 4 Aug = [A, b] Aug = 1 0 2 3 -1 2 2 -3 0 1 1 4 6 2 2 4 factor = -1 Aug = 1 0 2 3 0 2 4 0 0 1 1 4 6 2 2 4 factor = 0 Aug = 1 0 2 3 0 2 4 0 0 1 1 4 6 2 2 4 factor = 6 Aug = 1 0 2 3 0 2 4 0 0 1 1 4 0 2 -10 -14

1 -1 2 1

1 0 2 1

factor = 0.5000 Aug = 1 0 0 0 factor = 1 Aug = 1 0 0 0 factor = 14 Aug = 1 0 0 0

x = 0 0 0 0.4714 x = 0 0 -0.1143 0.4714 x = 0 0.2286 -0.1143 0.4714 x = -0.1857 0.2286 -0.1143 0.4714

0 2 0 2

2 4 -1 -10

3 0 4 -14

1 0 2 -5

x4

x3

0 2 0 0

2 4 -1 -14

3 0 4 -14

1 0 2 -5

x2

Eliminate second column

x1

1 0 2 1

0 2 0 0

2 4 -1 0

3 0 4 -70

1 0 2 -33

Eliminate third column1 0 2 -5

Back-substitution

Print all factor and Aug (do not suppress output)

Eliminate first column

Algorithm for Gauss elimination1. Forward eliminationfor each equation j, j = 1 to n-1 for all equations k greater than j (a) multiply equation j by akj /ajj (b) subtract the result from equation k This leads to an upper triangular matrix

2. Back-Substitution(a) determine xn from x n ! b /a (b) put xn into (n-1)th equation, solve for xn-1 (c) repeat from (b), moving back to n-2, n-3, etc. until all equations are solved( n1 ) n ( n1 ) nn

Operation CountImportant as matrix gets large For Gauss elimination Elimination routine uses on the order of O(n3/3) operations Back-substitution uses O(n2/2)

Operation CountOuter oop k 1 2 / k / n1 Inner oop i 2, n 3, n / k 1, n / n, n Addition/ ubtraction Multiplication/ ivision flops flops ( n 1)( n) ( n 2 )( n 1) / ( n k )( n k 1) / ( 1)( 2 ) ( n 1)( n 1) ( n 2 )( n) / ( n k )( n k 2 ) / ( 1)( 3 )

Total operation counts for elimination stage = 2n3/3 + O(n2) Total operation counts for back substitution stage = n2 + O(n)

Operation Count Number of flops (floating-point operations) for Naive Gauss eliminationBack n 10 100 1000 Elimination Sbustitution 705 671550 6.67 v 10 8 100 10000 1000000 otal lops 805 681550 6.68 v 10 6 2n 3 3 667 666667 6.67 v 10 8 ercentage e to Elimination 87.58% 98.53% 99.85%

Computation time increase rapidly with n Most of the effort is incurred in the elimination step Improve efficiency by reducing the elimination effort

Partial PivotingProblems with Gauss eliminationdivision by zero round off errors ill conditioned systems

Use Pivoting to avoid thisFind the row with largest absolute coefficient below the pivot element Switch rows (partial pivoting) complete pivoting switch columns also (rarely used)

RoundRound-off ErrorsA lot of chopping with more than n3/3 operations More important - error is propagated For large systems (more than 100 equations), roundoff error can be very important (machine dependent) Ill conditioned systems - small changes in coefficients lead to large changes in solution Round-off errors are especially important for illconditioned systems

IllIll-conditioned System

2x1 x2 = 3

2.1x1 x2 = 3

IllIll-Conditioned SystemConsidera11 b1 x 2 ! a x1 a a11 x1 a12 x 2 ! b1 12 12 a 21 x1 a 22 x 2 ! b2 ! a 21 x b2 x2 1 a 22 a 22

a11 a 21 Since slopes are almost equal $ a12 a 22

D!

a11 a 21

a 12 a 22

}0

Divided by small number

DeterminantCalculate determinant using Gauss eliminationa11 U ! a12 a13 ad ad 22 23 d ad 33 a1n ad 2n d ad 3n / ( n1 ) a nn ( n 1 ) nn

dd d et A ! et ! a11 a22 a33 - a U

Gauss Elimination ith Partial PivotingForward elimination for each equation j, j = 1 to n-1 first scale each equation k greater than j then pivot (switch rows) Now perform the elimination (a) multiply equation j by akj /ajj (b) subtract the result from equation

Partial (Ro ) Pivotingx1 x1 6 x1 2 x2 x2 2 x2 2 x3 2 x3 x3 2 x3 3 x4 3 x4 4 x4 4 x4 !1 ! 1 !2 !1

1 1 ?A bA! 0 6

0

1 2 2 3 1 1 1 4 2 2 2 4 1 2 3

For ard Elimination4 1 Interchange rows 1 & 4 6 2 2 1 2 2 3 1 f 21 ! 1/6 0 1 1 f 31 ! 0 4 2 f 41 ! 1/6 3 1 1 0 2 2 2 4 1 6 0 ( 2 ) ( 1) v f 7/3 7/3 7/3 5/6 21 0 1 1 4 2 ( 3 ) ( 1) v f 31 7/3 5/6 ( 4 ) ( 1) v f 41 0 1/3 5/3

For ard Elimination2 2 4 1 6 0 No interchange required 7/3 7/3 7/3 5/6 0 f 32 ! 3/7 1 1 4 2 f 42 ! 1/7 7/3 5/6 0 1/3 5/3 2 2 4 1 6 0 7/3 7/3 7/3 5/6 0 0 0 5 33/14 ( 3 ) ( 2 ) v f 32 0 2 2 5/7 ( 4 ) ( 2 ) v f 42 0

BackBack-Substitution2 2 4 1 6 0 7/3 7/3 7/3 5/6 0 0 2 2 5/7 0 0 5 33/14 0x 4 ! ( 33/14 ) /5 ! 33/70 x 3 ! ( 5/7 2 x 4 ) /2 ! 4/35 x 2 ! ( 5/6 7/3 x 4 7/3 x 3 ) / (7/3 ) ! 8/35 x 1 ! ( 1 4 x 4 2 x 3 2 x 2 ) /6 ! 13/70

Interchange rows 3 & 4

f 43 ! 0 13/70 8/35 T x! 4/35 33/70

MATLAB M-File: GaussPivot MPartial Pivoting (switch rows)

largest element in {x}

[big,i] = max(x)Partial Pivoting

index of the largest element

>> format short >> x=GaussPivot0(A,b) Aug = 1 0 2 3 1 -1 2 2 -3 -1 0 1 1 4 2 6 2 2 4 1 big = 6 i = Find the first pivot element and its index 4 ipr = 4 Aug = 6 2 2 4 1 -1 2 2 -3 -1 Interchange rows 1 and 4 0 1 1 4 2 1 0 2 3 1 factor = -0.1667 Aug = 6.0000 2.0000 2.0000 4.0000 1.0000 0 2.3333 2.3333 -2.3333 -0.8333 0 1.0000 1.0000 4.0000 2.0000 1.0000 0 2.0000 3.0000 1.0000 factor = 0 Aug = 6.0000 2.0000 2.0000 4.0000 1.0000 0 2.3333 2.3333 -2.3333 -0.8333 0 1.0000 1.0000 4.0000 2.0000 1.0000 0 2.0000 3.0000 1.0000 factor = 0.1667 Eliminate first column Aug = 6.0000 2.0000 2.0000 4.0000 1.0000 No need to 0 2.3333 2.3333 -2.3333 -0.8333 0 1.0000 1.0000 4.0000 2.0000 interchange 0 -0.3333 1.6667 2.3333 0.8333

Aug = [A b]

big = 2.3333 i = 1 ipr = 2 factor = 0.4286 Aug = 6.0000 0 0 0 factor = -0.1429 Aug = 6.0000 0 0 0 big = 2 i = 2 ipr = 4 Aug = 6.0000 0 0 0 factor = 0 Aug = 6.0000 0 0 0

Second pivot element and index No need to interchange

Back substitutionx = 0 0 0 0.4714 x = 0 0 -0.1143 0.4714 x = 0 0.2286 -0.1143 0.4714 x = -0.1857 0.2286 -0.1143 0.4714

2.0000 2.3333 0 -0.3333

2.0000 2.3333 0 1.6667

4.0000 -2.3333 5.0000 2.3333

1.0000 -0.8333 2.3571 0.8333

Eliminate second column2.0000 2.3333 0 0 2.0000 2.3333 0 2.0000 4.0000 -2.3333 5.0000 2.0000 1.0000 -0.8333 2.3571 0.7143

Third pivot element and index Interchange rows 3 and 42.0000 2.3333 0 0 2.0000 2.3333 2.0000 0 4.0000 -2.3333 2.0000 5.0000 1.0000 -0.8333 0.7143 2.3571

Save factors fij for LU Decomposition

Eliminate third column2.0000 2.3333 0 0 2.0000 2.3333 2.0000 0 4.0000 -2.3333 2.0000 5.0000 1.0000 -0.8333 0.7143 2.3571

TRUSS4 F45 F14 F24 K 2 F23 5

F35 F25 H 3 V3

1 H1 V1

E

F

F12

W = 100 kg

Statics: Force BalanceNode 1 Node 2 Node 3 Node 4 Node 5

F y ,1 ! V1 F14 si E ! 0 F x ,1 ! H 1 F12 F14 si E ! 0 F y , 2 ! F24 si F F25 si K ! 100 F x , 2 ! F12 F23 F24 cos F F25 cos K ! 0 F y , 3 ! V 3 F35 si H ! 0 F x , 3 ! F23 F35 cos H ! 0 F y , 4 ! F14 si E F24 si F ! 0 F x , 4 ! F14 cos E F24 cos F F45 ! 0 F y ,5 ! F25 si K F35 si H ! 0 F x ,5 ! F25 cos K F35 cos H F45 ! 0

Example: Forces in a Simple Truss1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 sin cos 0 0 0 0 0 0 1 0 sin cos 0 0 0 0 0 0 sin K cos K 0 0 0 0 sin K 0 cos K 0 0 0 0 sin H 0 0 sin H cos H 0 V1 0 0 1 0 100 0 V 3 F 0 12 0 F 0 14 0 ! F 0 23 0 F 0 24 0 F 1 25 0 F 0 35 0 F 1 45 0

0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 sin 0 cos 0 0

0 1 0 sin 0 cos 0 0 0 0

0 cos H

Define Matrices A and b in script filefunction [A,b]=Truss(alpha,beta,gamma,delta) A=zeros(10,10); A(1,1)=1; A(1,5)=sin(alpha); A(2,2)=1; A(2,4)=1; A(2,5)=cos(alpha); A(3,7)=sin(beta); A(3,8)=sin(gamma); A(4,4)=-1; A(4,6)=1; A(4,7)=-cos(beta); A(4,8)=cos(gamma); A(5,3)=1; A(5,9)=sin(gamma); A(6,6)=-1; A(6,9)=-cos(delta); A(7,5)=-sin(alpha); A(7,7)=-sin(beta); A(8,5)=-cos(alpha); A(8,7)=cos(beta); A(8,10)=1; A(9,8)=-sin(gamma); A(9,9)=-sin(delta); A(10,8)=-cos(gamma); A(10,9)=cos(delta); A(10,10)=-1; b=zeros(10,1); b(3,1)=100;

Gauss Elimination ith Partial Pivoting>> alpha=pi/6; beta=pi/3; gamma=pi/4; delta=pi/3; >> [A,b] = Truss(alpha,beta,gamma,delta) A = 1.0000 0 0 0 0.5000 0 1.0000 0 1.0000 0.8660 0 0 0 0 0 0 0 0 -1.0000 0 0 0 1.0000 0 0 0 0 0 0 0 0 0 0 0 -0.5000 0 0 0 0 -0.8660 0 0 0 0 0 0 0 0 0 0 b = 0 0 100 0 0 0 0 0 0 0 >> x = GaussPivot(A,b) x = 40.5827 0 48.5140 70.2914 -81.1655 34.3046 46.8609 84.0287 -68.6091 -93.7218 0 0 0 1.0000 0 -1.0000 0 0 0 0 0 0 0.8660 -0.5000 0 0 -0.8660 0.5000 0 0 0 0 0.7071 0.7071 0 0 0 0 -0.7071 -0.7071 0 0 0 0 0.7071 -0.5000 0 0 -0.8660 0.5000 0 0 0 0 0 0 0 1.0000 0 -1.0000

Banded matrix

Simple truss

Banded MatrixHBW: Half Band Width

Tridiagonal MatrixOnly three nonzero elements in each equation (3n instead of n2 elements) Subdiagonal, diagonal, superdiagonal Row Scaling (not implemented in textbook) -- scale the diagonal element to aii = 1 Solve by Gauss elimination

Tridiagonal Matrix f1 e 2 g1 f2 e3 g2 f3 1 g3 1 ei 1 fi 1 gi 1 e n1 1 f n 1 en x1 x 2 x 3 / ! x i / x g n 1 n 1 f n x n r1 r 2 r3 / ri / r n1 rn

Special case of banded matrix with bandwidth = 3 Save storage, 3 v n instead of n v n

Tridiagonal Matrix Forward eliminationek f k ! fk f g k1 k 1 k ! 2 , 3, - , n ! r ek r rk k k 1 fk 1

Use factor = ek / fk1to eliminate subdiagonal element Apply the same matrix operations to right hand side

Back substitutionxn ! rn fn k ! n 1, n 2, - , 3, 2 , 1

rk g k x k 1 xk ! fk

Hand Calculations: Tridiagonal Matrixx 0 0 1 1 2 2 x 1 5 0 2 ! 0 1 x 2 0.5 3 x 0 0 0.5 1.25 4 3 5 2 .5 3

(a) Forward elimination2 e f 2 ! f 2 2 g1 ! 5 ( 2 ) ! 1 f1 1 ! r e 2 r ! 5 2 ( 3 ) ! 1 r 2 2 f1 1 1 e 1 f3 ! f3 3 g 2 ! 2 ( 1) ! 1 f2 1 ! r e3 r ! 2 1 ( 1) ! 1 r 3 3 f2 2 1 e 0.5 f4 ! f4 4 g 3 ! 1.25 ( 0.5 ) ! 1 f3 1 ! r e4 r ! 3.5 0.5 (1) ! 4 r 4 4 f3 3 1

(b) Back substitutionx4 ! x3 ! r4 4 ! !4 f4 1 r3 g 3 x 4 1 ( 0.5 )( 4 ) ! !3 f3 1

r2 g 2 x 3 1 ( 1)( 3 ) ! !2 x2 ! f2 1 x1 ! r1 g 1 x 2 3 ( 2 )( 2 ) ! !1 f1 1

MATLAB M-file: Tridiag M-

Example: Tridiagonal matrixx 1 2 1 3 x 2 22 2 6 4 3 35.5 x 4 9 0 .5 ! x 4 7.75 0.5 3.25 ! 1.5 x 4 1.5 1.75 3 5 x 3 13 6 33

function [e,f,g,r] = example e=[ 0 -2 4 -0.5 1.5 -3]; f=[ 1 6 9 3.25 1.75 13]; g=[-2 4 -0.5 1.5 -3 0]; r=[-3 22 35.5 -7.75 4 -33];

[e,f,g,r] = example e = 0 f = 1.0000 g = -2.0000 r = -3.0000 22.0000 35.5000 -7.7500 4.0000 -33.0000 4.0000 -0.5000 1.5000 -3.0000 0 6.0000 9.0000 3.2500 1.7500 13.0000 -2.0000 4.0000 -0.5000 1.5000 -3.0000

x = Tridiag (e, f, g, r) x = 1 2 3 -1

-2

-3

Note: e(1) = 0 and g(n) = 0