for loop to create array

3 Ansichten (letzte 30 Tage)
Daniel Lennon
Daniel Lennon am 7 Dez. 2020
Beantwortet: Walter Roberson am 7 Dez. 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

Antworten (1)

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

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by