Issue with Matrix Dimensions
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Nilesh Naik
le 6 Fév 2022
Réponse apportée : Voss
le 6 Fév 2022
Hello All,
I am trying to run this code for some calculation but I seem be getting an disnion mismatch error. I have tried revisiting this code again and aagain but not able to find what I am missing. I am coming to the community to understand what is that I am missing Appreciate your help.
M=44;
N=11;
N1=6;
h=0.1;
Re=100;
for i=1:M
for j=1:N
u(i,j)=0;
v(i,j)=0;
si(i,j)=0;
om(i,j)=0;
end
end
for j=1:N1
y=(j-1)*h;
u(1,j)=-1.5+6*y*y;
si(1,j)=-0.5-1.5*y+2*y*y*y;
om(1,j)=-12*y;
end
for j=N1+1:N
y=(j-1)*h;
u(1,j)=-18*y*y+12*y-1.5;
si(1,j)=-6*y*y*y+6*y*y-1.5*y-0.5;
om(1,j)=36*y-12;
end
for i=(2:M-1)
si(i,N)=-0.5;
end
for j=(1:N)
y=(j-1)*h;
si(M,j)=-0.25+y*y*y-0.75*y;
u(M,j)=-0.75+3*y*y;
om(M,j)=-6*y;
end
for ite=(1:500)
for i=(2:M-1)
om(i,1)=-u(i:2)/h;
om(i,N)=u(i:N-1)/h;
end
for i=(2:M-1)
for j=(2:N-1)
si(i,j)=(si(i-1,j)+si(i+1,j)+si(i,j-1)+si(i,j+1)+om(i,j)*h*h)/4;
end
end
for i=(2:M-1)
for j=(2:N-1)
omx=(om(i+1,j)-om(i-1,j))/(2*h); %this line seems to be having an issue.
omy=(om(i,j+1)-om(i,j-1))/(2*h);
con=u(i,j)*omx+v(i,j)*omy;
om(i,j)=(((om(i-1,j)+om(i+1,j)+om(i,j-1)+om(i,j+1))-Re*con*h*h)/4);
end
end
end
for i=(1:M)
for j=(1:N)
u1(i,j)=1.5-6*y*y+u(i,j);
v1(i,j)=v(i,j);
end
end
0 commentaires
Réponse acceptée
William Rose
le 6 Fév 2022
The error occurs at lines
for ite=(1:500)
for i=(2:M-1)
om(i,1)=-u(i:2)/h; %error here
om(i,N)=u(i:N-1)/h; %error here
end
...
end
Change the lines to
om(i,1)=-u(i,2)/h;
om(i,N)=u(i,N-1)/h; % changed colon to comma
That works. Is it doing what you want? I don't know. But there is not an error now.
0 commentaires
Plus de réponses (1)
Voss
le 6 Fév 2022
The error I run into first is on this line:
om(i,N)=u(i:N-1)/h;
When i == 2, you have
om(2,11) = u(2:10)/0.1;
Just like the error message says, the left-hand side is a single scalar element and the right-hand side is a 1-by-9 vector. How to resolve that depends on what your intent is there, which I don't know.
Note that if that problem were resolved, then you'll have the same type of error on the next iteration with the previous line:
om(i,1)=-u(i:2)/h;
When i == 3, this is
om(3,1)=-u(3:2)/h;
because u(3:2) is empty and om(3,1) is a scalar.
Are these colon operations really supposed to be comma-separated lists (i.e., row/column indexing operations)? That is, u(i,N-1) and u(i,2)? Let me see if that runs:
M=44;
N=11;
N1=6;
h=0.1;
Re=100;
for i=1:M
for j=1:N
u(i,j)=0;
v(i,j)=0;
si(i,j)=0;
om(i,j)=0;
end
end
for j=1:N1
y=(j-1)*h;
u(1,j)=-1.5+6*y*y;
si(1,j)=-0.5-1.5*y+2*y*y*y;
om(1,j)=-12*y;
end
for j=N1+1:N
y=(j-1)*h;
u(1,j)=-18*y*y+12*y-1.5;
si(1,j)=-6*y*y*y+6*y*y-1.5*y-0.5;
om(1,j)=36*y-12;
end
for i=(2:M-1)
si(i,N)=-0.5;
end
for j=(1:N)
y=(j-1)*h;
si(M,j)=-0.25+y*y*y-0.75*y;
u(M,j)=-0.75+3*y*y;
om(M,j)=-6*y;
end
for ite=(1:500)
for i=(2:M-1)
om(i,1)=-u(i,2)/h;
om(i,N)=u(i,N-1)/h;
end
for i=(2:M-1)
for j=(2:N-1)
si(i,j)=(si(i-1,j)+si(i+1,j)+si(i,j-1)+si(i,j+1)+om(i,j)*h*h)/4;
end
end
for i=(2:M-1)
for j=(2:N-1)
omx=(om(i+1,j)-om(i-1,j))/(2*h); %this line seems to be having an issue.
omy=(om(i,j+1)-om(i,j-1))/(2*h);
con=u(i,j)*omx+v(i,j)*omy;
om(i,j)=(((om(i-1,j)+om(i+1,j)+om(i,j-1)+om(i,j+1))-Re*con*h*h)/4);
end
end
end
for i=(1:M)
for j=(1:N)
u1(i,j)=1.5-6*y*y+u(i,j);
v1(i,j)=v(i,j);
end
end
Runs without error.
0 commentaires
Voir également
Catégories
En savoir plus sur MATLAB Report Generator dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!