For loop is not repeating the specified number of times

2 ビュー (過去 30 日間)
Riley Stein
Riley Stein 2020 年 7 月 16 日
編集済み: SAA 2020 年 7 月 17 日
I am trying to model Butler-Volmer enzyme kinetics in Matlab. Currently, I am trying to produce an array of values for the rates based on a distance d parameter for all of the potentials the model will be at. The direction right now is to use a for loop for the d parameter, but the for loop is not repeating the specified number of times. Instead, a constant value is used for the for loop value (d=12). An array is created when no for loop is used, but then I have run into the problem that matrix dimensions don't match and the k0 * the rest can't be computed. For a description of how I want this to run, for every time point, the values kred and kox should be calculated for every d value.
The code in question (where the constants, a, F, R, T, and Eo are predefined):
v = 0.1;
tfinal = -1.5/v;
tStep = 0.1;
tspan = 0:tStep:tfinal;
t = tspan;
En = Ei + v * t;
for d = 4:0.1:12
k0 = 225000 * exp(-d);
kred = k0 * exp(((-a * F)/(R * T)) * (En - Eo));
kox = k0 * exp((((1-a) * F)/(R * T)) * (En - Eo));
end
And for future reference, I hope the solution can be something that is multipled in a differential equation, such as:
dAdt = -kred*A + kox*B

採用された回答

SAA
SAA 2020 年 7 月 17 日
編集済み: SAA 2020 年 7 月 17 日
you can only loop through integers, so you should do something like this:
.....
dt=4:0.1:12;
for d= 4:length(dt)
.....
end

その他の回答 (0 件)

カテゴリ

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