I don't know what's wrong with the function.

2 次查看(过去 30 天)
It is a function consisting of t, Q, and C. I was trying to express this in MATLAB. But a problem arose in expressing Q. But I don't know why it's a problem. The red part seems to be wrong, but I can't fix it.
function dCdt = name(t,C,dz,u_column,D,F,H)
dCdt = zeros(column_Number*(Nz+1),1);
dQdt = name2(t,Q,C,H,Nz,column_Number)
C(1)=0.2;
for k = 1 : 4
for i = 1 : 100
dCdz(i) = 1./(dz).*(C(i)-C(i-1));
d2Cdz2(i) = 1./(dz^2.).*(C(i)-2.*C(i-1)+C(i-2));
% dQdt(i) = H*dCdt(i);
dCdt(i) = D.*d2Cdz2(i) - u_column*dCdz(i) + F*dQdt(i);
end % for i = 1 : 100
end % for k = 1 : 4
end % function
function dQdt = name2(t,Q,C,H)
for k = 1 : 4
for i = 1 : 100
Q(i) = H*C(i);
dQdt(i) = H*dCdt(i);
end % for i = 1 : 100
end % for k = 1 : 4
end % function
  2 个评论
VBBV
VBBV 2022-2-14
put a snapshot of error ( in red color text)
Walter Roberson
Walter Roberson 2022-2-14
for k = 1 : 4
for i = 1 : 100
Q(i) = H*C(i);
dQdt(i) = H*dCdt(i);
end % for i = 1 : 100
end % for k = 1 : 4
The assignments index at i but k is not used inside the nested loop. The exact same thing is going to be done every iteration of the for k loop -- the output is going to be exactly the same as if you did not have any for k loop.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by