for loop to create array

1 view (last 30 days)
Daniel Lennon
Daniel Lennon on 7 Dec 2020
Answered: Walter Roberson on 7 Dec 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

Answers (1)

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

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!