I would like to create a matrix using a for loop

4 visualizaciones (últimos 30 días)
Rodrigo Blas
Rodrigo Blas el 13 de Abr. de 2020
Comentada: Rodrigo Blas el 13 de Abr. de 2020
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

Respuesta aceptada

Rik
Rik el 13 de Abr. de 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.

Más respuestas (0)

Categorías

Más información sobre Performance and Memory en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by