Use Matlab to compute the first 10 iterates with Jacobi Method for equations
u + 4v = 5
v + 2w = 2
4u + 3w = 0
Code
a=[4 0 3;1 4 0;0 1 2]
b=[0;5;2]
x=[0;0;0]
y=x;
for k=1:10
disp('iteration')
disp(k)
x
for i=1:3
y(i)=b(i);
for j=1:3
if i==j
y(i)=y(i);
else
y(i)=y(i)-a(i,j)*x(j);
end
end
y(i)=(1/a(i,i))*y(i);
end
x=y;
end
Output
Get Answers For Free
Most questions answered within 1 hours.