I am trying to create a loop where a variable changes and the answer is saved in the matrix below

조회 수: 1 (최근 30일)
A1=9200000;A2=420000000;A3=350000;n1=0;n2=5.3;n3=7.65;Ea1=108400;Ea2=350000;Ea3=525000;R=82.057;
k1mat = zeros(1,29);k2mat = zeros(1,29);k3mat = zeros(1,29);c1mat = zeros(1,29);c2mat = zeros(1,29);c3mat = zeros(1,29);
Tmat = 500:25:1200
for i = [500:25:1200]
T=(i+25)
c1=(3.6000*10^-04)*(1/R*T);
%c4=0
c3 = (2.4000*10^-04)*(1/R*T);
c4 = 0.0664*(1/R*T);
k1=(A1*T^(n1)*exp(-Ea1/(R*T)));
k2=(A2*T^(n2)*exp(-Ea2/(R*T)));
k3=(A3*T^(n3)*exp(-Ea3/(R*T)));
k1mat(T) = k1;
k2mat(T) = k2;
k3mat(T) = k3;
c1mat(T) = c1;
c3mat(T) = c3;
c4mat(T) = c4;
end
I have looked through multiple answers but cannot find answers on something like this specifically. It is producing matrices of zeros.... Thank you!

답변 (1개)

Ameer Hamza
Ameer Hamza 2020년 10월 2일
편집: Ameer Hamza 2020년 10월 2일
Check this code and compare it with your code to find the issue
A1=9200000;A2=420000000;A3=350000;n1=0;n2=5.3;n3=7.65;Ea1=108400;Ea2=350000;Ea3=525000;R=82.057;
k1mat = zeros(1,29);k2mat = zeros(1,29);k3mat = zeros(1,29);c1mat = zeros(1,29);c2mat = zeros(1,29);c3mat = zeros(1,29);c4mat = zeros(1,29);
Tmat = 500:25:1200;
for i = 1:numel(Tmat)
T = Tmat(i)+25;
c1=(3.6000*10^-04)*(1/R*T);
%c4=0
c3 = (2.4000*10^-04)*(1/R*T);
c4 = 0.0664*(1/R*T);
k1=(A1*T^(n1)*exp(-Ea1/(R*T)));
k2=(A2*T^(n2)*exp(-Ea2/(R*T)));
k3=(A3*T^(n3)*exp(-Ea3/(R*T)));
k1mat(i) = k1;
k2mat(i) = k2;
k3mat(i) = k3;
c1mat(i) = c1;
c3mat(i) = c3;
c4mat(i) = c4;
end
  댓글 수: 2
Nikolaj Kloch
Nikolaj Kloch 2020년 10월 2일
You are incredible. This is for a combustion class and you have saved me! What was the numel command in the "for i = 1:numel(Tmat)"
Ameer Hamza
Ameer Hamza 2020년 10월 2일
편집: Ameer Hamza 2020년 10월 2일
I am glad to be of help!!!
numel() is number of elements in vector. For a 1D vector, it is same as length().

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by