for loop to create array

1 visualizzazione (ultimi 30 giorni)
Daniel Lennon
Daniel Lennon il 7 Dic 2020
Risposto: Walter Roberson il 7 Dic 2020
I am trying to create three arrays of concentration. Each array uses some of the same constants, however different calues for Kd and Ji.
The only variable changing in the equation to create a array is time (1 to 300 years).
Any help would be great:
%Given through all
JN = (60 * 10^15)/ 2.12;
Co = 415;
e = 2.71828182845;
V = 4 *10^21;
%Ji and Kd for each part 1,2,3
%1
Ji1=(9.1*10^15)/2.12;
KD1 = (2.5 * 10^-2);
%2
Ji2=(9.1*10^15)/2.12;
KD2 = (1.8 * 10^-2);
%3
Ji3=(14*10^15)/2.12;
KD3 = (2 * 10^-2);
%create arrays
t=1:300;
C1=[];
C2=[];
C3=[];
%Calculation of each part using equation given
for i = 1:300
C1= ((JN + Ji1)/(KD1 * V))+(Co - ((JN + Ji1)/(KD1 * V)))*e^(-KD1*t(i));
end
for i = 1:300
C2= ((JN + Ji2)/(KD2 * V))+(Co - ((JN + Ji2)/(KD2 * V)))*e^(-KD2*t(i));
end
for i = 1:300
C3= ((JN + Ji3)/(KD3 * V))+(Co - ((JN + Ji3)/(KD3 * V)))*e^(-KD3 * t(i));
end

Risposte (1)

Walter Roberson
Walter Roberson il 7 Dic 2020
No loops
C1= ((JN + Ji1)/(KD1 * V))+(Co - ((JN + Ji1)/(KD1 * V)))*exp(-KD1*t);
Notice exp() and notice t is not subscripted

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by