필터 지우기
필터 지우기

For loop is not repeating the specified number of times

조회 수: 3 (최근 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 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