Skip to main content
provided simpler solution
Source Link
bbgodfrey
  • 63.1k
  • 18
  • 94
  • 169

In general, when FindRoot is initialized with two initial guesses for each variable, it uses them to estimate how the function to be solved varies locally with those variables. Giving initial guesses that are far apart, as in the question, defeats this purpose. Trying something like

initVals2 = FindRoot[EndCondition[α1, β1] == 0, {α1, 6, 8}, {β1, 0.01, 0.03}] // Chop (* {α1 -> 0, β1 -> 0.0194729} *) 

avoids the error cited in the question.

Simpler Solution

Define

ode = {Expand[dec1], dea1, des1, dek1} /. paramFinal; 

(Expand is used to eliminate a spurious singularity at c = 0.)

sol = NDSolve[{ode, c[1/2] == 0, a[1/2] == 0, k[0] == 41/10, s[0] == 95}, {c, a, s, k}, {t, 0, 1/2}]; 

from which the initial conditions on c and a can be obtained from

{(c[0] /. sol), a[0] /. sol} // Chop (* {{-2.66636*10^-7}, {0.0194729}} *) 

In fact, c actually is equal to zero, as can be seen by evaluating

ode[[1]] /. c[t] -> 0 (* Derivative[1][c][t] == 0 *) 

If desired, the remaining equations can be solved by

sol1 = NDSolve[{ode[[2 ;; 4]] /. c[t] -> 0, a[1/2] == 0, k[0] == 41/10, s[0] == 95}, {a, s, k}, {t, 0, 1/2}]; a[0] /. sol1 (* {0.0194729} *) 

In general, when FindRoot is initialized with two initial guesses for each variable, it uses them to estimate how the function to be solved varies locally with those variables. Giving initial guesses that are far apart, as in the question, defeats this purpose. Trying something like

initVals2 = FindRoot[EndCondition[α1, β1] == 0, {α1, 6, 8}, {β1, 0.01, 0.03}] // Chop (* {α1 -> 0, β1 -> 0.0194729} *) 

avoids the error cited in the question.

In general, when FindRoot is initialized with two initial guesses for each variable, it uses them to estimate how the function to be solved varies locally with those variables. Giving initial guesses that are far apart, as in the question, defeats this purpose. Trying something like

initVals2 = FindRoot[EndCondition[α1, β1] == 0, {α1, 6, 8}, {β1, 0.01, 0.03}] // Chop (* {α1 -> 0, β1 -> 0.0194729} *) 

avoids the error cited in the question.

Simpler Solution

Define

ode = {Expand[dec1], dea1, des1, dek1} /. paramFinal; 

(Expand is used to eliminate a spurious singularity at c = 0.)

sol = NDSolve[{ode, c[1/2] == 0, a[1/2] == 0, k[0] == 41/10, s[0] == 95}, {c, a, s, k}, {t, 0, 1/2}]; 

from which the initial conditions on c and a can be obtained from

{(c[0] /. sol), a[0] /. sol} // Chop (* {{-2.66636*10^-7}, {0.0194729}} *) 

In fact, c actually is equal to zero, as can be seen by evaluating

ode[[1]] /. c[t] -> 0 (* Derivative[1][c][t] == 0 *) 

If desired, the remaining equations can be solved by

sol1 = NDSolve[{ode[[2 ;; 4]] /. c[t] -> 0, a[1/2] == 0, k[0] == 41/10, s[0] == 95}, {a, s, k}, {t, 0, 1/2}]; a[0] /. sol1 (* {0.0194729} *) 
Source Link
bbgodfrey
  • 63.1k
  • 18
  • 94
  • 169

In general, when FindRoot is initialized with two initial guesses for each variable, it uses them to estimate how the function to be solved varies locally with those variables. Giving initial guesses that are far apart, as in the question, defeats this purpose. Trying something like

initVals2 = FindRoot[EndCondition[α1, β1] == 0, {α1, 6, 8}, {β1, 0.01, 0.03}] // Chop (* {α1 -> 0, β1 -> 0.0194729} *) 

avoids the error cited in the question.