# Nested For loop with NDsolve

I am solving two simple differential equation using NDsolve.

solution = NDSolve[{X'[t] == μ*S[t]*X[t]/(k + S[t]),
S'[t] == -μ*S[t]*X[t]/(0.664252*(k + S[t])),
X[0] == 10,S[0] == 300}, {X, S}, {t, 0, 40.7}]
bacteria[t_] = X[t] /. solution;
food[t_] = S[t] /. solution;
qq = Table[310 - bacteria[t] - food[t], {t, time}];
error = MapThread[Plus,Abs[(exp[[All, 1]] - qq)/exp[[All, 1]]*100/298]]


I need to evaluate error for different values of k and μ in order to check the values of k and μ for which error is less than 5%. exp and time are results which I have.

When I try to put my code in a For-loop, it fails.

For[μ = 0.1, μ <= 1, μ = μ + 0.1,
k = 100
solution = NDSolve[{X'[t] == μ*S[t]*X[t]/(k + S[t]),
S'[t] == -μ*S[t]*X[t]/(0.664252*(k + S[t])),
X[0] == 10, S[0] == 300}, {X, S}, {t, 0, 40.7}]
bacteria[t_] = X[t] /. solution;
food[t_] = S[t] /. solution;
qq = Table[310 - bacteria[t] - food[t], {t, time}];
error = MapThread[Plus,Abs[(exp[[All, 1]] - qq)/exp[[All, 1]]*100/298]]
Print[error]]


The above is giving me errors and I do not get any results. My plan is to use this For-loop to vary μ and then use a nested loop for varying k.

There are some simple mistakes in your code that must be corrected before we can see if there is a more serious error. 1) exp and time must have values defined for them. 2) semicolons (;) are needed after k = 100 and solution = NDSolve[...] –  m_goldberg May 4 at 10:30