Plot an equation graph

Hi. I am working on lineer equation methods, as a Jacobi Method. I want to solve given equations and plot its roots.
My solving code here, it works good.
A = [3 -1 1;1 4 -2;-3 2 6]; %Equations
b = [15;-13;11]; %Solution
[~,n] = size(A);
X = zeros(n,2);
X(:,1)'
for iteration=1:4 %Solve 4 steps
for i=1:n
sum = 0;
for j=1:n
if (i~=j)
sum = sum + A(i,j)*X(j,1);
end
end
X(i,2) = (b(i)- sum) / A(i,i);
end
disp(iteration)
X;
X(:,1) = X(:,2);
X(:,2)'
end
And a plot code are here;
%PLOTTING
set(gcf, 'Position', get(0, 'Screensize'));
for i=1:n
%Jacobi Graph
subplot(1,2,1);
plot(A(1:i),X(1:i),'b','LineWidth',3);
hold on;
plot(A(i),X(i),'r*','Color',[1 0 0],'LineWidth',8);
grid on;
title(sprintf('Jacobi Z(4) value (%d) = %.15f',n,X(i)));
ylabel('Jacobi','Color',[1 0 1],'FontSize',24);
pause(1);
end
It has to be something like this i think;
But it is not. How can I solve this problem ? I looked at many times but could not find it. If I solve this problem, I will add a graph one more. This is why I used subplot.

Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!