CONTINUE THE WORK OF THIS CODE PLEASE USE GAUSS SEIDEL METHO
CONTINUE THE WORK OF THIS CODE PLEASE.. USE GAUSS SEIDEL METHOD ......ONCE I get it my goal is to use it on a 39*9 matrix so want to make sure how it works on a small matrix , I already know the answers... so just checking .. please make sure you understand
A=[5 -2 3;-3 9 1;2 -1 -7]
B=[-1;2;3]
T=inv(A)*B
n=length(B)
for k=2:6
for i= 1:n
for j=1:n
if j<i
sum_1=sum_1+A(i,j)/(A(i,i))*T(j,k)
end
if j>i
sum_2=sum_2+A(i,j)/(A(i,i))*T(j,k-1)
end
end
T(i,k)=B(i)/(A(i,i))-sum_1-sum_2
end
sum_3=0
norm_1=(norm(T(i,k))-norm(T(i,k-1)))/(norm(T(i,k)))
T_er=abs(T(i,k)-T(i,k-1))
end
Solution
This is working code in MATLAB change according to your need.
A=[5 -2 3;-3 9 1;2 -1 -7]
B=[-1;2;3]
N = 3
C_n = 0.1
n = length(B);
X = zeros(n,1);
e = ones(n,1);
iteration = 0;
while max(e) > C_n%check error
iteration = iteration + 1;
Z = X; % save current values to calculate error later
for i = 1:N
j = 1:N; % define an array of the coefficients\' elements
j(i) = []; % eliminate the unknow\'s coefficient from the remaining coefficients
Xtemp = X; % copy the unknows to a new variable
Xtemp(i) = []; % eliminate the unknown under question from the set of values
X(i,1) = (B(i,1) - sum(A(i,j) * Xtemp)) / A(i,i);
end
Xs = X;
e = sqrt((X - Z).^2);
end
%% Display Results
Xs
iteration

