In regard to contour error

1 Ansicht (letzte 30 Tage)
bryan Kim
bryan Kim am 15 Okt. 2015
Beantwortet: Martin Schätz am 15 Okt. 2015
uhm.. it is so long. but i want to receive advice
x=25:50;
nx=length(x)
y=25:50;
ny=length(y)
h=1;
for i=25:50
for j=25:50
v(i,j)=0;
npbc(i,j)=0;
roh(i,j)=0;
perm(i,j)=8.854e-12;
end
end
for i=25:50
npbc(i,25)=2;
end
for j=25:50
npbc(i,1)=3;
end
for j=25:50
v(50,j)=0;
npbc(50,j)=1;
end
for i=25:50
v(i,50)=100;
npbc(i,50)=1;
end
v(50,50)=50;
npbc(50,50)=1;
k=0;
eps=1.e-07;
alpha=1.5;
reler=eps+1;
while reler>eps
k=k+1
vsum=0;
chgsum=0;
for i=25:50
for j=25:50
id=npbc(i,j);
if id ==1, continue, end
old=v(i,j);
switch id
case 0
v1=v(i-1,j);
v2=v(i+1,j);
v3=v(i,j-1);
v4=v(i,j+1);
case 2
v1=v(i+1,j);
v2=v(i+1,j);
v3=v(i,j-1);
v4=v(i,j+1);
case 3
v1=v(i-1,j);
v2=v(i+1,j);
v3=v(i,j+1);
v4=v(i,i+1);
otherwise
v1=v(i+1,j);
v2=v(i+1,j);
v3=v(i,j+1);
v4=v(i,j+1);
end
v(i,j)=(v1+v2+v3+v4+h*h*roh(i,j)/perm(i,j))/4;
chg=v(i,j)-old;
v(i,j)=old+alpha*chg;
chgsum=chgsum+abs(chg);
vsum=vsum+abs(v(i,j));
end
end
reler=chgsum/vsum;
end
%
contour(x,y,v,30)
xlabel('x')
ylabel('y')
Error using contour (line 81) The size of X must match the size of Z or the number of columns of Z.
Error in FDM_laplace_matlab11111 (line 75) contour(x,y,v,30)

Antworten (1)

Martin Schätz
Martin Schätz am 15 Okt. 2015
Your size of v is 50x50, and you want to get element 51 (v2=v(i+1,j) and i=50). If you want to use code as that you have to change end of your for cycle to 49.
Also contour needs X Y and Z as 2D matrix. Check the contour help for examples.

Kategorien

Mehr zu Triangulation Representation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by