how to solve "Matrix dimensions must agree."
1 view (last 30 days)
Show older comments
When i run this program it give me error in line 32. MathLab code attach here please guide me.
i need to sum all the Rm & Rk in the for loops.
for m=1:3
r_m=dr*m+dr*(m-(m-1))/2; %% r_m for R_m+ %%
Rm(m)=dr/((r_m+dr/2)*dteta*dz*k_pipe); %% r direction %%
for z=1:5
Rk(z)=dz/(r_m*dteta*dr*k_water); %% z direction %%
end
Rh=1/(h_out*A);
if (m==1)
v=pi()*(dr*m)^2*dz; %%%
elseif (m>1&&m<3)
v=pi()*((dr*m)^2-(dr*(m-1)^2))*dz; %% r element volume %%
Cm=c*rau_p*v; %% rau_p/w?
line 32 s=sum(Rm+Rk+Rh); %??
dt=Cm/(1/s)); %% ??
end
end
for p=1:10
if (z==1)
T(P+1,m,k)=(dt/Cm)*(((T(p,m+1)-T(p,m))/Rm)+((T(p,m)-T(p,m+1))/Rm)+((T(p,z+1)-T(p,z))/(Rk)))+T(p,m,k);
elseif (z>1&&z<5)
T(P+1,m,k)=(dt/Cm)*(((T(p,m+1)-T(p,m))/Rm)+((T(p,m+1)-T(p,m))/Rm)+((T(p,z+1)-T(p,z))/(Rk)+((T(p,z)-T(p,z-1))/(Rk))))+T(p,m,k);
elseif (z==5)
T(P+1,m,k)=(dt/Cm)*(((T(p,m+1)-T(p,m))/Rm)+((T(p,m)-T(p,m+1))/Rm)+((T(p,z)-T(p,z-1))/(Rk)))+T(p,m,k);
end
end
disp('T out [K]: ');disp('T(Z_n_elem)');
plot(dz*(1:Z_n_elem),T);
xlabel('x (m) '),ylabel('T (K) ');
9 Comments
Walter Roberson
on 21 May 2022
"in here r_m is function that i built"
You repeatedly invoke your function with no parameters.
Rk(k)=dz/(r_m*dteta*dr*k_water); %% z direction
Notice the r_m has no () after it. In MATLAB when you define a true function and mention its name without the @ operator, that invokes the function passing in no parameters.
Answers (1)
Walter Roberson
on 21 May 2022
T(P+1,m,k)=(dt/Cm(m))*(((T(p,m)-T(p,m-1))/Rm(m))+((T(p,m+1)-T(p,m))/Rm(m))+((T(p,k)-T(p,k-1))/Rk(k)))+T(p,m,k);
nothing prevents that from executing when m==1
Before that point you test m>1 but you have "end" on that test so you are no longer protected.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!