I would like to create a matrix using a for loop

4 ビュー (過去 30 日間)
Rodrigo Blas
Rodrigo Blas 2020 年 4 月 13 日
コメント済み: Rodrigo Blas 2020 年 4 月 13 日
function rn=Ljallo_f_q1(T,R,pnh3,po2)
for i=1:3
A=zeros(3,1);
B=zeros(3,1);
C=zeros(3,1);
rn=zeros(3,1);
rn(i)=A(i)/(B(i)*C(i));
A(i)=3.4*10^-8*exp(21700/(R.*T(i)))*pnh3*po2^(.5);
B(i)=1+8*10^-2*exp(4400/(R.*T(i)))*po2^(.5);
C(i)=1+1.6*10^-3*exp(25500/(R.*T(i)))*pnh3;
end
pnh3=.046; %%torr
po2=.068; %%torr
R=62.364*1000; %%cm^3*torr/K*g-mol
T=zeros(3,1);
T(1)=473;
T(2)=673;
T(3)=800;
z=Ljallo_f_q1(T,R,pnh3,po2);
>> Ljallo_s_q1
>> z
z =
0
0
NaN
I would like to create amatrix rn with 3 values(rn(1) rn(2) rn(3)) using a for loop

採用された回答

Rik
Rik 2020 年 4 月 13 日
If you had used the debugging tools, you would have noticed that your variables are reset every iteration.
You need to move assignments like A=zeros(3,1) outside of the loop.
  1 件のコメント
Rodrigo Blas
Rodrigo Blas 2020 年 4 月 13 日
Fixed. Thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePerformance and Memory についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by