Error: Unable to perform assignment because the left and right sides have a different number of elements.
5 views (last 30 days)
Show older comments
I'm trying 2d velocity equation in tridigonal system. I stuck in the rhs of tridigonal equation. I got error "Unable to perform assignment because the left and right sides have a different number of elements."

when i use this equation i couldn't rectify my programme. I'm taking this equation in three multiple equation for top and bottom boundary and interior nodes.
ymax=20; m=80; dy=ymax/m; %y=dy:dy:ymax; %'i'th row
xmax=1; n=20; dx=xmax/n; %'j'th column
tmax=100; nt=500; dt=tmax/nt; t=0:dt:tmax;
tol=1e-2;
max_Iteration=1;
UWALL=ones(m,nt); %INITIAL VALUE
UOLD=zeros(m,nt);
UNEW=0; %BOUNDARY VALUE
VOLD=zeros(m,nt);
CNEW=0;COLD=CNEW*ones(m,nt);CWALL=ones(1,length(t));
TNEW=0;TOLD=TNEW*ones(m,nt);TWALL=ones(1,length(t));
A=zeros([1,m]);
B=A;
C=A;
D=A;
T=TOLD; U=UOLD;
%============CALCULATE INTEGRAL USING SIMPHONS RULE==============%
F = @(ymax) ymax;
a = 0;
b = 20;
N1 = 80;
h = b-a/N1;
s = 0;
for w = 0:20
if w == 0 || w == 20
p = 1;
elseif mod(w,2) ~= 0
p = 4;
else
p = 2;
end
X = a+w*h;
S = s+p*F(ymax);
end
I = h/3*S;
%================================================%
while max_Iteration>tol
for j=2:nt
for i=2:m-1
if i==2
D(i)=UOLD(i,j)-(dt*UOLD(i,j)*(-U(i,j-1)+UOLD(i,j)-UOLD(i,j-1)/2*dx))+(dt*(UWALL(j)-2*UOLD(i,j)+UOLD(i-1,j)/2*dy^2))+(dt*E2*(gr^(-1/4)*cos(phi)*I*diff(TWALL(j),xmax)+(1/2)*sin(phi)*(TWALL(j)+TOLD(i,j))))-(dt*VOLD(i,j)*(UOLD(i-1,j)-UWALL(j)/4*dy))-(dt*(UWALL(j)/2*dy^2));
elseif i==m-1
D(i)=UOLD(i,j)-(dt*UOLD(i,j)*(-U(i,j-1)+UOLD(i,j)-UOLD(i,j-1)/2*dx))+(dt*(UOLD(i+1,j)-2*UOLD(i,j)+UNEW/2*dy^2))+(dt*E2*(gr^(-1/4)*cos(phi)*I*diff(TNEW,xmax)+(1/2)*sin(phi)*(TNEW+TOLD(i,j))))-(dt*VOLD(i,j)*(UNEW-UOLD(i+1,j)/4*dy))-(dt*(UNEW/2*dy^2));
else
D(i)=UOLD(i,j)-(dt*UOLD(i,j)*(-U(i,j-1)+UOLD(i,j)-UOLD(i,j-1)/2*dx))+(dt*(UOLD(i+1,j)-2*UOLD(i,j)+UOLD(i-1,j)/(2*dy^2)))-(dt*VOLD(i,j)*(UOLD(i-1,j)-UOLD(i+1,j)/4*dy))+(dt*E2*(gr^(-1/4)*cos(phi)*I*diff(T,xmax)+(1/2)*sin(phi)*(T+TOLD(i,j))));
end
end
max_Iteration=max_difference;
end
end
Kindly assist me to finish well.
2 Comments
Answers (1)
Walter Roberson
on 20 Jun 2023
TNEW=0;TOLD=TNEW*ones(m,nt);TWALL=ones(1,length(t));
TWALL is numeric.
D(i)=UOLD(i,j)-(dt*UOLD(i,j)*(-U(i,j-1)+UOLD(i,j)-UOLD(i,j-1)/2*dx))+(dt*(UWALL(j)-2*UOLD(i,j)+UOLD(i-1,j)/2*dy^2))+(dt*E2*(gr^(-1/4)*cos(phi)*I*diff(TWALL(j),xmax)+(1/2)*sin(phi)*(TWALL(j)+TOLD(i,j))))-(dt*VOLD(i,j)*(UOLD(i-1,j)-UWALL(j)/4*dy))-(dt*(UWALL(j)/2*dy^2));
diff(TWALL(j),xmax) with xmax == 1, is the "first" numeric difference of TWALL(j) . diff(X,1) is equivalent to X(2:end)-X(1) for vector X. But TWALL(j) is a scalar, and the 2:end of a scalar is empty, so diff(TWALL(j),1) is going to be empty. That "empty" contaminates everything else in the calculation; the right hand side is going to be empty.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!