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

1 view (last 30 days)
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!

Answers (1)

Ameer Hamza
Ameer Hamza on 2 Oct 2020
Edited: Ameer Hamza on 2 Oct 2020
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 Comments
Nikolaj Kloch
Nikolaj Kloch on 2 Oct 2020
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 on 2 Oct 2020
Edited: Ameer Hamza on 2 Oct 2020
I am glad to be of help!!!
numel() is number of elements in vector. For a 1D vector, it is same as length().

Sign in to comment.

Categories

Find more on Loops and Conditional Statements 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!