I would like to create a matrix using a for loop
조회 수: 4 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Performance and Memory에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!