Presentation is loading. Please wait.

Presentation is loading. Please wait.

Numerical Methods.  Forward Elimination of Unknowns: In this step, the unknown is eliminated in each equation starting with the first equation. This.

Similar presentations


Presentation on theme: "Numerical Methods.  Forward Elimination of Unknowns: In this step, the unknown is eliminated in each equation starting with the first equation. This."— Presentation transcript:

1 Numerical Methods

2  Forward Elimination of Unknowns: In this step, the unknown is eliminated in each equation starting with the first equation. This way, the equations are reduced to one equation and one unknown in each equation.  Back Substitution: In this step, starting from the last equation, each of the unknowns is found. Prof. S. M. Lutful Kabir, BRAC University2

3  There will be a total of (n-1) steps of forward elimination.  At the end of (n-1) steps of forward elimination, we get a set of equations that look like 3

4  Now the equations are solved starting from the last equation as it has only one unknown.  Then the second last equation, that is the (n-1) th equation, has two unknowns: x n and x n+1 and, but x n is already known. This reduces the (n-1) th equation also to one unknown. Back substitution hence can be represented for all equations by the formula for n = n-1, n-2, …2, 1 and 4

5  The two methods are the same, except in the beginning of each step of forward elimination, a row switching is done based on the following criterion.  Criteria: If there are n equations, then there are n-1 forward elimination steps. In the k th step of forward elimination, one finds the elements of the kth column below k-1 row |a kk |, |a k+1,k |,……….|a nk |  Then, if the maximum of these values is |a pk | in the p th row, then switch rows p and k.  The other steps of forward elimination are the same as the Gauss elimination method.  The back substitution steps stay exactly the same as the Gauss elimination method. 5

6 % Defining ‘a’ and ‘b’ matrices of the equation % [a][x]=[b], [x] is the unknown a=[20 15 10; -3 -2.249 7; 5 1 3]; b=[45 1.751 9]; % n is the dimension of a matrix n=3; Prof. S. M. Lutful Kabir, BRAC University6

7 % FORWARD ELIMINATION % start with 1st row as pivot row, next is the second row and similarly % upto (n-1)th row for PivotRow=1:n-1 % finding maximum absolute value of the elements in the column % equal to pivot row and below the pivot row MaxPosition=PivotRow; MaxValue=abs(a(PivotRow,PivotRow)); for kk= PivotRow+1 : n if abs(a(kk,PivotRow))>MaxValue MaxValue=abs(a(kk,PivotRow)); MaxPosition=kk; end Prof. S. M. Lutful Kabir, BRAC University7

8 % if row other than pivotrow is found to have maximum element % interchange all elements of that row with the corresponding % elements of pivot row if MaxPosition ~= PivotRow a for jj=PivotRow : n temp=a(PivotRow,jj); a(PivotRow,jj)=a(MaxPosition,jj); a(MaxPosition,jj)=temp; end temp=b(PivotRow); b(PivotRow)=b(MaxPosition); b(MaxPosition)=temp; a end Prof. S. M. Lutful Kabir, BRAC University8

9 % now assign Pivot element as diagonal element of the pivot row PivotElement = a(PivotRow,PivotRow); % in order to eliminate elements below pivot element start with % PivotRow+1 and repeat upto last row for i = PivotRow+1 : n % start with removal element as the element just below % pivot element and then the element below and so on RemovalElement = a(i,PivotRow); for j = PivotRow:n a(i,j) = a(i,j) - a(PivotRow,j) * RemovalElement / PivotElement; end % make corresponding operation of the element of b matrix b(i) = b(i) - b(PivotRow) * RemovalElement / PivotElement; end 9

10 % BACK SUBSTITUTION % find the value of xn from the last equation x(n)=b(n)/a(n,n); % start finding value of x(n-1), then x(n-2) and so on upto x3, x3 and % x1 using the equations (n-1)th, (n-2)th, upto 2nd, 1st equations % sequentially in backward direction for kk=n-1:-1:1 sumtotal=0; for jj=kk+1:n sumtotal=sumtotal+a(kk,jj)*x(jj); end x(kk)=(b(kk)-sumtotal)/a(kk,kk); end a b x Prof. S. M. Lutful Kabir, BRAC University10

11 Solve the following simultaneous linear equations using Gaussian elimination method -x 1 +4x 2 +3x 3 = 18….….….(1) 3x 1 +2x 2 -x 3 = -2….….….(2) 2x 1 -3x 2 +7x 3 = 13….….….(3) Prof. S. M. Lutful Kabir, BRAC University11

12 Thanks Prof. S. M. Lutful Kabir, BRAC University12


Download ppt "Numerical Methods.  Forward Elimination of Unknowns: In this step, the unknown is eliminated in each equation starting with the first equation. This."

Similar presentations


Ads by Google