Вы находитесь на странице: 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



Problem
Solve the boundary value problem for
d
2

dx
2
=1.2510
12
c
-5000x
where h=1 pm


Plot the solution using
i) PINV
ii) Gauss Seidel Method (error<1nV)
Initial Solution=5exp(-5000x)
iii) Gauss elimination with pivoting





Graph
PINV:
Elapsed time is 0.047521 seconds.







Gauss Elimination with Pivoting:
Elapsed time is 0.444923 seconds.








Gauss Seidel Method:
Elapsed time is 3.965348 seconds.








Combined Graph:








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;



end
x=0: h: 10^- 4;
B=zer os( 1, 101) ;
B( 1, 1) =5;
B( 1, 101) =0;

f or i =2: 101
B( i ) =1. 25. *10^12. *exp( - 5. *10^5. *x( i ) ) . *( h^2) ;
end
t i c
e=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 c
s=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
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: 1
sum=b( i ) ;

f or j =i +1: n
sum=sum- a( i , j ) . *x( j ) ;
end
x( 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^- 4
x( 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
end
x( i ) =sum. / a( i , i ) ;

end

xsol =xr ef - x;

f i ni sh=0;
f or i =1: 101
i f xsol ( i ) >10^- 9
f i ni sh=1;
end
end

i f ( f i ni sh==0)
br eak;
end




xr ef =x;
% check=check+1;
% i f check==1000
% br eak;
% end
end

pl ot ( xr ef , ' g' ) ;

t oc

Вам также может понравиться