Azzera filtri
Azzera filtri

For loop is not repeating the specified number of times

3 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

SAA
SAA il 17 Lug 2020
Modificato: SAA il 17 Lug 2020
you can only loop through integers, so you should do something like this:
.....
dt=4:0.1:12;
for d= 4:length(dt)
.....
end

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by