Matlab Program For Jacobi Method
Matlab Program For Jacobi Method
NASIR HUSSAIN1
KHURRAM SHAHZAD2
1-(MS-FELLOW)PAISTAN INSTITUTE OF ENGINEERING AND APPLIED SCIENCES, NILORE, ISLAMABAD
2-(PHD. STUDENT)PAISTAN INSTITUTE OF ENGINEERING AND APPLIED SCIENCES, NILORE, ISLAMABAD
1)
clc;
A=[10 -1 2 0; -1 11 -1 3; 2 -1 10 -1; 0 3 -1 8]
B=[6; 25; -11; 15]
n=length(B);
x0=[0 ; 0; 0; 0];
x1=[];
s=1000;
conv=1e-10;
for q=1:s
for m=1:n
sum=0;
for k=1:n
if m==k
continue
end
sum=sum+A(m,k)*x0(k);
end
x1(m)=(B(m)-sum)/A(m,m);
x1;
end
if abs(norm(x1)-norm(x0))<=conv
solution=x1;
iter_no=q;
break;
end
for p=1:n
x0(p)=x1(p);
end
end
solution
iter_no
2)
% Any norm of a vector
clc;
nth_val=3;
x=[4 5 6 3];
for k=1:4
y(k)=x(k)^nth_val;
end
sum=0;
for k=1:n
sum=sum+y(k);
end
norm_x=sum^(1/nth_val)
(End of document)