필터 지우기
필터 지우기

plot command is not work in Gauss Seidel Method

조회 수: 1 (최근 30일)
suketu vaidya
suketu vaidya 2020년 12월 4일
답변: suketu vaidya 2020년 12월 4일
A = [
1 0 -1 0 0 0 0
-1 1 1 0 0 0 0
0 -1 2 -1 0 0 0
0 -1 0 2 0 1 0
0 -1 -1 0 2 1 1
0 0 1 -1 0 2 -1
0 0 0 -1 1 -1 2
];
b = [0 0 0 0 0 20 0]';
x=[1 1 1 1 1 1 1];
n=size(x,1);
normVal=Inf;
tol=1e-5; itr=0;
%%Gauss Seidel Method
while normVal>tol
x_old=x;
for i=1:n
sigma=0;
for j=1:i-1
sigma=sigma+A(i,j)*x(j);
end
for j=i+1:n
sigma=sigma+A(i,j)*x_old(j);
end
x(i)=(1/A(i,i))*(b(i)-sigma);
end
itr=itr+1;
normVal=norm(x_old-x);
end
%%
fprintf('system solution : \n%f\n%f\n%f\n%f in %d iterations',x,itr);
hold on
plot(itr,x, '+')
xlim([0 10])
ylim([0 2])
hold off
end

채택된 답변

John D'Errico
John D'Errico 2020년 12월 4일
When you tell us that something does not work, you need ot explain why you THINK it does not work. In fact, plot worked perfectly well there. At least, it tiried to work as well as it could.
itr
itr =
2
x
x =
0 1 1 1 1 1 1
plot(itr,x, '+')
So itr is the number 2. x is a vector. What did you expect it to do?
  댓글 수: 2
suketu vaidya
suketu vaidya 2020년 12월 4일
hello ,
i is not shosws full vactor x . i means x1 = 0 x2 = 1 x3=1 and so on . i want a graph that shows x1,x2,x3 in x axist and on y axis value of x1,x2,x3 and so on
suketu vaidya
suketu vaidya 2020년 12월 4일
easy way i try to plot ans of gauss seidel method

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

suketu vaidya
suketu vaidya 2020년 12월 4일
right ans is
hold on
plot(x,'o')

카테고리

Help CenterFile Exchange에서 Linear Algebra에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by