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

 Réponse acceptée

Walter Roberson
Walter Roberson le 5 Déc 2020

1 vote

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 commentaires

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 le 6 Déc 2020
thank you man ,I really appreciated you're support.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Version

R2020b

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by