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 个评论
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 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!