Error: Unable to perform assignment because the left and right sides have a different number of elements.

5 views (last 30 days)
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
Unrecognized function or variable 'E2'.
Kindly assist me to finish well.

Answers (1)

Walter Roberson
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.
diff() is only derivative when you are working with sym or symfun -- or for the case where the first parameter is an anonymous function and the second parameter is a symbolic variable
  1 Comment
Nathi
Nathi on 21 Jun 2023
@Walter Roberson You exactly got where i went wrong. I didn't approach this the right way. we have to notice in this term have partial derivative of integrals.
For that purpose, i'm using diff(TWALL(j),xmax). According to me, it is differentiate w.r.to x . but we notice one thing in the term i.e., 'T' term is into the integral. so, we can use TWALL is a function of integral w.r.to Y. If we use T is a function of integral, then we have to modify the integration part using simphons rule.
i.e.,
%============CALCULATE INTEGRAL USING SIMPHONS RULE==============%
F = @(ymax) TWALL; i'm using TWALL instead of 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;
And i'm changing this equation [ diff(I,xmax) ] instead of [ I*diff(TWALL, xmax) ]
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*(gr^(-1/4)*cos(phi)*diff(I,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));
but i got the same error :"Unable to perform assignment because the left and right sides have a different number of elements". I really stuck in this part. how to approach this integrodifferential and include it in my equation ?
please suggest and give some idea about this.

Sign in to comment.

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!