For loop is not repeating the specified number of times

2 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by