I have a problem with workspace ı can not see variables while code is working perfectly also ı can not see any plotting

 채택된 답변

Walter Roberson
Walter Roberson 2020년 12월 5일

1 개 추천

The code you posted is a function. Local variables for a function disappear after the function returns; you would have to put in a breakpoint before the end of the function to see the local variables.
Your posted code does not plot anything.

댓글 수: 3

function GaussSeidel
close all
clear all
n=10;
for i1=1:n
b(i1)=i1
for j1=1:n
a(i1,j1)=((i1*(-1)^j1)/70 +(j1*(-1)^i1)/50);
end
sumvalue=0;
for j1=1:i1-1
sumvalue=sumvalue+abs(a(i1,j1));
end
for j1=i1+1:n
sumvalue=sumvalue+abs(a(i1,j1));
end
a(i1,i1)=sumvalue;
end
b=transpose(b);
Detofa=det(a)
eigenvalueofa=eig(a);
conditionnumberofa=max(abs(eigenvalueofa))/min(abs(eigenvalueofa))
inverseofa=inv(a);
Xinv=inverseofa*b;
error=a*Xinv-b;
L2error=sqrt(transpose(error)*error);
for i1=1:n
X(i1)=1.0;
end
X=transpose(X);
L2errors=0.01
L2errora=1.0
iter=0;
lambda=0.4;
while L2errora>L2errors
iter=iter+1;
Xprevious=X;
for i1=1:10
sumvalue=0;
for j1=1:i1-1
sumvalue=sumvalue+a(i1,j1)*X(j1);
end
for j1=i1+1:n
sumvalue=sumvalue+a(i1,j1)*X(j1);
end
x(i1)=(b(i1)-sumvalue)/a(i1,i1);
end
errora=(X-Xprevious)./X*100;
X=lambda*X+(1-lambda)*Xprevious;
L2errora=sqrt(transpose(errora)*errora);
errorvector(iter)=L2errora;
continue
end
figure
semilogy(errorvector,"-ro",...
"LineWidth",2,...
"MarkedSize",10,...
"MarkedEdgeColor",
"b")
title("error")
xlabel("iteration")
ylabel("l2error")
* ı mention about this code , in course same code with teacher but he can see the plots but ı can not see any thing , there is no error also
x(i1)=(b(i1)-sumvalue)/a(i1,i1);
That is the only place in the code that you use lower-case x as a variable name.
semilogy(errorvector,"-ro",...
"LineWidth",2,...
"MarkedSize",10,...
"MarkedEdgeColor",
"b")
That needs a few changes:
semilogy(errorvector, "-ro",...
"LineWidth", 2,...
"MarkerSize", 10,...
"MarkerEdgeColor", "b")
ataberk kaplica
ataberk kaplica 2020년 12월 6일
thank you man ,I really appreciated you're support.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

제품

릴리스

R2020b

태그

Community Treasure Hunt

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

Start Hunting!

Translated by