System of Linear EQ
System of Linear EQ
Gauss Elimination:
Elimination:
Pseudo code: 1. For k=1 to n-1 // processing column (1st row without 1st column 0) 2. For i=k+1 n // for every row 3. Factor=A i,k/A k,k // find pivot 4. For j=k+1 to n // subtract 1st row from ith row after dividing by pivot 5. A i,j=A i,j factor*A k,j 6. B i=B i- factor*B k // subtract constant after dividing by pivot
Back Substitution:
Pseudo code: 1. X n=B n/A n,n 2. For i=n-1 to 1 3. Sum=B i 4. For j=i+1 to n 5. Sum=Sum-A i,j*X j 6. X i=Sum/A i,i
Partial Pivoting:
Process: 1. Find largest element of processing column 2. Swap the two column 3. Swap value of b at this two columns Pseudo code: 1. P=k 2. Big=|A k,k| 3. For i=k+1 to n 4. Temp=|a i,k| 5. If(Temp>Big) 6. Big=Temp 7. P=I //starting column
8. If(p!=k) 9. For j=k to n 10. Temp=A p,j 11. A p,j=A k,j 12. A k,j=Temp 13. Temp=Bp 14. Bp=Bk 15. Bk=Temp
// is largest value is the first one? // if not, then swap the coefficient of X, A[]
Scaling:
1. The maximum coefficient in each row can be 1 2. To do: divide all of the coefficient in a row with its largest coefficient
Pseudo code: 1. 2. 3. 4. 5. 6. 7. 8. 9. K Big=A k,k For(i=k+1 to n) Temp=A i,k If(Temp>Big) Big=Temp For(i=k to n) A k,i=A k,i/Big B k=B k/Big
** The equations are not scaled, but scaled values of the elements are used to determine whether pivoting is to be implemented.
Gauss(A, B, n, X, tol, er) 1. Arry S[n] 2. er=0 3. For i=1 to n // find the largest value in each column 4. S i=abs(A i,1) 5. For j=2 to n 6. If(abs(A i,j)>S i) 7. S i=abs(A i,j) 8. Call Eliminate(A, S, n, B, tol, er) // now eliminate to make upper triangle 9. If(er!=-1) // terminate condition (detect near zero) 10. Call Substitute(A, n, B, X)
Eliminate(A, S, n, B, X) 1. For k=1 to n-1 // processing column (ith row without 1st column 0)
2. Call Pivot(A, B, S, n, k) // find pivot 3. if( abs(A k,k/S k)< tol // in scaling if round-off error exceeds tolerance then return -1 and exit 4. Er=-1 5. Exit 6. For i=k+1 to n //for every row 7. factor=A i,k/A k,k 8. For j=k+1 to n // subtract ith row from the processing row after dividing by pivot. 9. A i,j=A i,j factor*A k,j 10. B i=B i factor*B k // subtract the constant after dividing by pivot 11. if(abs(A k,k/S k)< tol) // in scaling if error exceeds tolerance then return -1 and exit 12. er= -1
Pivot(A, B, S, n, k) 1. P=k 2. Big=abs(A k,k/S k) 3. For i=k+1 to n 4. Temp=abs(A i,k/S i) 5. If(Temp>Big) 6. Big=Temp 16. P=i 7. 8. If p!=k 9. For j=k to n 10. Temp=A p,j 11. A p,j=A k,j 12. A k,j=Temp 13. Temp=B p 14. B p=B k 15. B k=Temp 16. Temp= S p 17. S p=S k 18. S k=Temp
Substitute (A, n, B, X) 1. X n=B n/A n,n 2. For i=n-1 to 1 3. Sum=0 4. For j=i+1 to n 5. Sum=Sum+A i,j*X j 6. X i=(B i-Sum) / A i,i
Gauss Jordan:
Gauss-Jordan is a variation of Gauss Elimination. Here equation is eliminated from all other equations rather than the subsequent ones like Gauss elimination. Then there makes a identity matrix. So no back substitution is required to obtain solution. The complexity is same as Gauss elimination.
Process:
1. 2. 3. 4.
Partial pivoting before normalize Normalize first row (make 1) Find pivot Eliminate
Pseudo code: 1. For k=1 to n-1 2. Normalize() // make first column=1 (to make identity matrix) 3. For i = 1 to n 4. If( i!=k) 5. Factor=A i,k 6. For j=1 to n 7. A i,j=A i,j - factor*A k,j 8. B i=B i-factor*B k
LU Decomposition:
[A]{X} = {B} [A]{X} {B} = 0 After Gauss elimination [U]{X} {D}=0 1 Suppose [L] = 0 0 That has property that, [L]{ [U]{X} {D} } = [A]{X} {B} So , [L][U] = [A] [L]{D} = {B} 0 1 0 0 0 1
f21 1
f31 f32 1
Pseudo code:
Decompose(A, n) 1. For k=1 to n-1 2. For i=k+1 to n 3. Factor=A i,k/A k,k 4. A i,k=Factor 5. For j=k+1 to n 6. A i,j=A i,j Factor*A k,j
Substitute(A, n, B, X) 1. For i=2 to n // forward substitution 2. Sum=B i 3. For j=1 to i-1 4. Sum=sum-A i,j * B j 5. B i=Sum // {D} found 6. 7. X n=B n/A n,n // back substitute (find {X}) 8. For i=n-1 to -1 9. Sum=0 10. For j=i+1 to n 11. Sum=sum+A I,j *X j 12. X i=(B i sum)/A I,i
Decompose(A, n, tol, O, S, Er) 1. For i=1 to n 2. O i=i 3. S i=abs(A i,1) 4. For j=2 to n 5. If (abs (Ai,j)>S i) 6. S i= abs(A i,j) 7. For k=1 to n-1 8. Pivot(A, O, S, n, k) 9. If( abs(A o(k),k/S o(k) < tol 10. Er=-1 11. Print A o(k),k/S o(k) 12. Exit 13. For i=k+1 to n 14. Factor = A o(i),k/A o(k),k 15. A o(i),k = Factor
16. For j=k+1 to n 17. A o(i),j = A o(i),j Factor * A o(k),j 18. If(abs (A o(k),k/S o(k) < tol 19. Er= - 1 20. Print A o(k),k/S o(k) Pivot(A, O, S, n, k) 1. P=k 2. Big=abs(A o(k),k/ S o(k)) 3. For i=k+1 to n 4. Temp=abs(A o(i),k/ S o(i)) 5. if( Temp> Big) 6. Big= Temp 7. P=i 8. Temp=O p 9. O p=O k 10. O k=Temp Substitute(A, O, n, B, X) 1. For i=2 to n 2. Sum=B o(i) 3. For j=1 to i-1 4. Sum=sum- A o(i),j *B o(j) 5. B o(i)=sum 6. X n=B o(n)/A o(n),n 7. For i=n-1 to -1 8. Sum=0 9. For j=i+1 to n 10. Sum=sum+ A o(i),j * X j 11. X i=( B o(i) Sum)/ A o(i),j