A = [4 -1 0;
-1 4 -1;
0 -1 4];
b = [15; 10; 10];
x = [0; 0; 0];
n = 10;
for k = 1:n
x_old = x;
x(1) = (b(1) - A(1,2)*x(2) - A(1,3)*x(3)) / A(1,1);
x(2) = (b(2) - A(2,1)*x(1) - A(2,3)*x(3)) / A(2,2);
x(3) = (b(3) - A(3,1)*x(1) - A(3,2)*x(2)) / A(3,3);
if norm(x - x_old, inf) < 1e-6
break;
end
end
fprintf('x = %f\n', x(1));
fprintf('y = %f\n', x(2));
fprintf('z = %f\n', x(3));⚠️Content was pasted as plain text and auto-formatted as a code block. Use the Code Block button in the editor for proper formatting.