ANM Assignment
ANM Assignment
ANM Assignment
ASSIGNMENT
1.LU Factorization by Doolittle's method
MATLAB code
%%
clear;
clc;
pause;
clc;
%%
B=B1';
[m,n]=size(A);
ordo=length(A);
if m~=n
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
MATRIX U
U=
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;
pause;
clc;
[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
x'
OUTPUT
a=
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;
pause
clc;
absoluteerror=abs(x - n)
percenterror=relativeerror*100
OUTPUT
absoluteerror =
0.0033
relativeerror =
8.2362e-05
percenterror =
0.0082