Upload
ayaz-masud-sezan
View
218
Download
0
Embed Size (px)
Citation preview
7/30/2019 Solution of Linear Algebric Equations Using MATLAB
1/9
EEE 212: Numerical Technique Laboratory
No. of Experiment : 5
Name of Experiment : Solution of Simultaneous Linear Algebric
Equations
Date of Performance: 23-05-2012
Date of Submission: 30-05-2012
Tahmid Sami Rahman
0906016
Department: EEE
Section: A
Md. Ayaz Masud
0906021
Department: EEE
Section: A
7/30/2019 Solution of Linear Algebric Equations Using MATLAB
2/9
Problem
Solve the boundary value problem for
= 1.2510 where h=1
Plot the solution using
i) PINVii) Gauss Seidel Method (error
7/30/2019 Solution of Linear Algebric Equations Using MATLAB
3/9
Graph
PINV:
Elapsed time is 0.047521 seconds.
7/30/2019 Solution of Linear Algebric Equations Using MATLAB
4/9
Gauss Elimination with Pivoting:
Elapsed time is 0.444923 seconds.
7/30/2019 Solution of Linear Algebric Equations Using MATLAB
5/9
Gauss Seidel Method:
Elapsed time is 3.965348 seconds.
7/30/2019 Solution of Linear Algebric Equations Using MATLAB
6/9
Combined Graph:
7/30/2019 Solution of Linear Algebric Equations Using MATLAB
7/9
Appendix
Code for the Solution
cl ear al l ; h=10 - 6; A=zer os( 100, 100) ; A( 1, 1)=1; A( 101, 101) =1; f or i =2: 100
j =i ; A( i , j - 1) =1; A( i , j ) =- 2;
A( i , j +1) =1;
endx=0: h: 10 - 4; B=zeros( 1, 101) ; B( 1, 1)=5; B( 1, 101)=0;
f or i =2: 101B( i ) =1. 25. *10 12. *exp( - 5. *10 5. *x( i ) ) . *( h 2) ; endt i ce=pi nv( A) *B' ; t oc
di sp( e) ;
% pl ot ( d, ' r ' ) ; % hol d on;
pl ot ( e, ' b' ) ; hol d on;
a=A; b=B;
aj i =0;
t i cs=si ze( a) ; f or i =1: s(1) - 1
f or j =i +1: s( 1) aj i =a( j , i ) ;
f or k=1: s( 2) a( j , k) =a( j , k) - ( aj i . / a( i , i ) ) . *a( i , k) ;
end
7/30/2019 Solution of Linear Algebric Equations Using MATLAB
8/9
b( j ) =b( j ) - ( aj i . / a( i , i ) ) . *b( i ) ; end
end
di sp( a) ; di sp( b) ;
x=b;
n=s( 2) ; sum=0;
x( n) =b( n) . / a( n, n) ;
f or i =n- 1: - 1: 1sum=b( i ) ;
f or j =i +1: nsum=sum- a( i , j ) . *x(j ) ;
endx( i ) =sum. / a( i , i ) ;
end
%di sp( x) ;
pl ot ( x, ' o' ) ;hol d on;
t oc%gauss sei del
t i c
x=b; h=10 - 6; i =1; f or h=0: 10 - 6: 10 - 4x(i ) =5. *exp( - 5000. *h) ; i =i +1;
end
xr ef =x;
check=0;
whi l e( 1) f or i =1: 101
sum=b( i ) ; f or j =1: 101
i f i ~=j sum=sum- ( a( i , j ) . *x( j ) ) ; end
endx( i ) =sum. / a( i , i ) ;
7/30/2019 Solution of Linear Algebric Equations Using MATLAB
9/9
end
xsol =xref - x;
f i ni sh=0;
f or i =1: 101i f xsol ( i ) >10 - 9
f i ni sh=1; end
end
i f( f i ni sh==0) break;
end
xref =x; % check=check+1; % i f check==1000% br eak; % endend
pl ot ( xref , ' g' ) ;
t oc