I would like to create a matrix using a for loop

2 views (last 30 days)
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

Accepted Answer

Rik
Rik on 13 Apr 2020
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.

More Answers (0)

Categories

Find more on Polynomials in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!