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

1 回表示 (過去 30 日間)
채원 이
채원 이 2022 年 2 月 14 日
コメント済み: Walter Roberson 2022 年 2 月 14 日
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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by