for loop to create array

3 ビュー (過去 30 日間)
Daniel Lennon
Daniel Lennon 2020 年 12 月 7 日
回答済み: Walter Roberson 2020 年 12 月 7 日
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

回答 (1 件)

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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by