I don't know what's wrong with the function.
조회 수: 4 (최근 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개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!