Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

ANM Assignment

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

ANM

ASSIGNMENT
1.LU Factorization by Doolittle's method

MATLAB code

%%

clear;

clc;

disp(' DOOLITTLE METHOD ');

disp('Press ENTER to continue');

pause;

clc;

%%

A=input('ENTER A SQUARE MATRIX A ');

B1=input('ENTER MATRIX D ');

B=B1';

[m,n]=size(A);

ordo=length(A);

if m~=n

disp('[A] IS NOT A SQURE METRIX ');

return

end

U=zeros(m);

L=zeros(m);

for j=1:m

L(j,j)=1;

end

for j=1:m

U(1,j)=A(1,j);

end

for i=2:m

for j=1:m
for k=1:i-1;

s1=0;

if k==1

s1=0;

else

for p=1:k-1

s1=s1+L(i,p)*U(p,k);

end

end

L(i,k)=(A(i,k)-s1)/U(k,k);

end

for k=i:m

s2=0;

for p=1:i-1

s2=s2+L(i,p)*U(p,k);

end

U(i,k)=A(i,k)-s2;

end

end

end

Y1(1)=B(1);

for k=2:ordo

sigma1=0;

for j=1:k-1

sigma1=sigma1+L(k,j)*Y1(j);

Y1(k)=B(k)-sigma1;

end

end

Y=Y1';

X(ordo)=Y(ordo)/U(ordo,ordo);

for k=ordo-1:-1:1
sigma2=0;

for j=k+1:ordo;

sigma2=sigma2+U(k,j)*X(j);

X(k)=(Y(k)-sigma2)/U(k,k);

end

end

disp('MATRIX A')

disp('MATRIX L')

disp('MATRIX U')

disp('MATRIX Y')

disp('MATRIX X')

X'
OUTPUT
ENTER A SQUARE MATRIX A [3 2 7;2 3 1;3 4 1]

ENTER MATRIX D [4 5 7]

MATRIX A

A=

3 2 7

2 3 1

3 4 1

MATRIX L

L=

1.0000 0 0

0.6667 1.0000 0

1.0000 1.2000 1.0000

MATRIX U

U=

3.0000 2.0000 7.0000

0 1.6667 -3.6667

0 0 -1.6000
MATRIX Y

Y=

4.0000

2.3333

0.2000

MATRIX X

ans =

0.8750

1.1250

-0.1250
2 Gauss Elimination Method

MATLAB CODE

clear;

clc;

disp(' GAUSS ELIMINATION METHOD ');

disp('Press ENTER to continue');

pause;

clc;

a=input('[a|d] matrix ');

[m,n]=size(a);

for j=1:m-1

for z=2:m

if a(j,j)==0

t=a(j,:);a(j,:)=a(z,:);

a(z,:)=t;

end

end

for i=j+1:m

a(i,:)=a(i,:)-a(j,:)*(a(i,j)/a(j,j));

end

end

x=zeros(1,m);

for s=m:-1:1

c=0;

for k=2:m

c=c+a(s,k)*x(k);

end
x(s)=(a(s,n)-c)/a(s,s);

end

disp('the values= ');

x'
OUTPUT

[a|d] matrix [1 10 -1 3;2 3 20 7;10 -1 2 4]

a=

1.0000 10.0000 -1.0000 3.0000

0 -17.0000 22.0000 1.0000

0 0 -118.7059 -31.9412

the values=

ans =

0.3751

0.2894

0.2691
3.ABSOLUTE ERROR, RELATIVE ERROR, &PERCENTAGE ERROR

MATLAB CODE
clear;

clc;

disp(' error calculation ' );

disp('Press ENTER to continue');

pause

clc;

x=input('enter the value ');

n=input('enter the round of value ');

absoluteerror=abs(x - n)

relativeerror=(absoluteerror / min(abs(x), abs(n)))

percenterror=relativeerror*100
OUTPUT

enter the value 39.46325

enter the round of value 39.46

absoluteerror =

0.0033

relativeerror =

8.2362e-05

percenterror =

0.0082

You might also like