Please help me correct the following code to get the gauss s

Please help me correct the following code to get the gauss seidel method .... please send back the code and make sure is correct the first aproximation for x1=-.2 for x2=0.156 and for x3=-.508

%Trial

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=A(i,j)/(A(i,i))*T(j,k)

end

if j>i

sum_2=A(i,j)/(A(i,i))*T(j,k-1)

end

T(i,k)=B(i)/(A(i,i))-sum_1-sum_2

end

sum_3=0

end

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

A=[5 -2 3;-3 9 1;2 -1 -7];
B=[-1;2;3];

init = [-0.2 0.156 0.508];
y = [0 0 0];
%calculating upto 4 iterations
for m = 1:4
for i = 1:3
y(i) = B(i)/A(i,i);
for j = 1:3
if (j ~= i)
y(i) = y(i) - ((A(i,j) / A(i,i))*init(j));
init(i) = y(i);
end
end
fprintf(\'x%d = %f \', i, y(i));
end
fprintf(\'\ \');
end

%-----------------------------------------------------------------------------------------

Output:

x1 = -0.442400 x2 = 0.018311 x3 = -0.557587
x1 = 0.141877 x2 = 0.331469 x3 = -0.435388
x1 = 0.193820 x2 = 0.335205 x3 = -0.421081
x1 = 0.186731 x2 = 0.331252 x3 = -0.422542

Please help me correct the following code to get the gauss seidel method .... please send back the code and make sure is correct the first aproximation for x1=-
Please help me correct the following code to get the gauss seidel method .... please send back the code and make sure is correct the first aproximation for x1=-

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site