Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 1-by-2.

4 ビュー (過去 30 日間)
I am getting an error on line that is in bold, italics, and underlined stating that I have different sized matrixes but have no clue how this could've happened. I thought I used the same methodology for both sides and should therefore they should be the same size. Any help you can provide would be greatly appreciated.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% properties of flow
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
r = 0.2; % meters, radius of cylinder
vFreeStream = 5; % m/s, free stream velocity
lpus = 50; % N/m, lift per unit span
rho = 1.18; % k/m^3, air density of free-stream
tol = 1.0e-6; % tolerance
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% kutta-juokowski circulation equation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
gamma = lpus / (vFreeStream*rho); % circulation
cl = lpus / (0.5*r*rho*(vFreeStream^2)) % lift coefficient
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% this section will help us print later in the code
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
minX = -1; % m, minimum location of x
maxX = 1; % m, max location of x
numX = 101; % number of spots
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% do the same for y values
minY = -1;
maxY = 1;
numY = 101;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% mesh spacing & loop
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
dx = (maxX-minX) / (numX-1);
dy = (maxY-minY) / (numY-1);
for ii = 1:numX % loop over x values
for jj = 1:numY
xVals(ii,jj) = minX+dx*(ii-1);
yVals(ii,jj) = minY+dy*(jj-1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Polar coordinates with assumed origin
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
r2 = (xVals(ii,jj)^2+yVals(ii,jj)^2); % p-thag
r2 = max(r2,tol);
r2 = sqrt(r);
theta = atan2(yVals(ii,jj),xVals(ii,jj));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% applying potential flow theory
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% cyclinder with freestream velocity
psi(ii,jj) = vFreeStream*r2*sin(theta)*(1-(r/r2)^2);
phi(ii,jj) = vFreeStream*r2*cos(theta)*(1+(r/r2)^2);
vr = (1-(r/r2)^2)*vFreeStream*cos(theta);
vTheta = -(1+(r/r2)^2)*vFreeStream*sin(theta);
% vortex
phi(ii,jj) = phi(ii,jj)-gamma/(2.*pi)*theta;
psi(ii,jj) = psi(ii,jj)+gamma/(2.*pi)*log(r2/r);
vr = vr+0;
vTheta = vTheta-gamma/(2.*pi*r2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% source terms
lamb = -2.*pi*r*vr; %lambda term
vr(ii,jj) = lamb/(2.*pi*r);
phi(ii,jj) = lamb*log(r)/(2.*pi);
psi(ii,jj) = lamb*theta/(2.*pi);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if(r2<r)
vmag(ii,jj) = -1;
cp(ii,jj) = 2;
else
vmag(ii,jj) = sqrt(vr.^2+vTheta.^2);
cp(ii,jj) = 1-(vmag(ii,jj)/vFreeStream)^2;
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% plotting (directly from report, with changed variables for my code)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(1)
clf(1)
hold on
[c1,h1]=contour(xVals(:,:),yVals (:,:), psi(:,:),'k','LineWidth',4,[-10:1:10]); %plots the x vs t
clabel (c1, h1, -10:2:10, "fontsize", 24);
[c2,h2]=contour(xVals(:,:),yVals (:,:), cp(:,:),'g','LineWidth',4,[-2:0.1:1]); %plots the x vs t
clabel (c2, h2, -2:0.2:1, "fontsize", 24);
hold off
t1=title('Coplot of Stream Function (\psi) and C_p')
x1=xlabel('Position, x (m)') %x-axis label
y1=ylabel('Position, y (m)') %y-axis label
set(t1,'FontSize',24) %change fontsize
set(x1,'FontSize',24) %change fontsize
set(y1,'FontSize',24) %change fontsize
%Now only plot the Vel Mag, what does it look like
figure(2)
clf(2)
hold on
[c2,h2]=contourf(xVals(:,:),yVals (:,:), vmag(:,:),'k','LineWidth',0.5,[0:0.5:8]); %plots the x vs t
clabel (c2, h2, 0:1:8, "fontsize", 24);
t1=title('Velocity Mag(|V|)')
x1=xlabel('Position, x (m)') %x-axis label
y1=ylabel('Position, y (m)') %y-axis label
set(t1,'FontSize',24) %change fontsize
set(x1,'FontSize',24) %change fontsize
set(y1,'FontSize',24) %change fontsize
%Now only plot the Cp, what does it look like
figure(3)
clf(3)
hold on
[c2,h2]=contourf(xVals(:,:),yVals (:,:), cp(:,:),'k','LineWidth',0.5,[-2:0.1:1]); %plots the x vs t
clabel (c2, h2, -2:0.2:1, "fontsize", 24);
t1=title('Pressure Coefficent(C_p)')
x1=xlabel('Position, x (m)') %x-axis label
y1=ylabel('Position, y (m)') %y-axis label
set(t1,'FontSize',24) %change fontsize
set(x1,'FontSize',24) %change fontsize
set(y1,'FontSize',24) %change fontsize
%Now one more, a coplot of Psi and Phi
figure(4)
clf(4)
hold on
[c1,h1]=contour(xVals(:,:),yVals (:,:), psi(:,:),'k','LineWidth',4,[-10:1:10]); %plots the x vs t
clabel (c1, h1, -10:2:10, "fontsize", 24);
[c2,h2]=contour(xVals(:,:),yVals (:,:), phi(:,:),'r','LineWidth',4,[-10:1:10]); %plots the x vs t
clabel (c2, h2, -10:2:10, "fontsize", 24);
t1=title('Coplot of Stream Function (\psi) and Velocity Potential (\phi)')
x1=xlabel('Position, x (m)') %x-axis label
y1=ylabel('Position, y (m)') %y-axis label
set(t1,'FontSize',24) %change fontsize
set(x1,'FontSize',24) %change fontsize
set(y1,'FontSize',24) %change fontsize

回答 (1 件)

Voss
Voss 2022 年 11 月 28 日
This line, which is a few lines above the line with the error:
vr(ii,jj) = lamb/(2.*pi*r);
makes vr a 1-by-2 vector when it is executed when ii = 1 and jj == 2.
That's what causes the error a little later on, because this expression
sqrt(vr.^2+vTheta.^2)
will now return a 1-by-2 vector, which cannot be stored in the scalar "slot" given by
vmag(ii,jj)
I guess the solution is to change vr here:
vr(ii,jj) = lamb/(2.*pi*r);
to some other variable name, say vr_all:
vr_all(ii,jj) = lamb/(2.*pi*r);
because it seems like you want to store vr for all ii and all jj, but vr is already a scalar variable you are using inside the loops.

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by