0
$\begingroup$

I am trying to solve the following problem: find the smallest value of $b$ such that the inverse of the solution u[p] given by NDSolveValue is never less than 1.

f[b_, v_] := NDSolveValue[{u''[p] + u[p] == 1/(2*(b*v)^2) + 3/2*u[p]^2, 
    u[0] == 0, u'[0] == 0}, u, {p, 0.1, 10}];

To do this for a given value of v, here 0.2, I have written the following code

g[q_] := MinValue[{(1/f[q, 0.2][p]), 10 > p > 0.1}, p];
NSolve[g[q] == 1, q]

The function g[q] seems to work fine, g[15] returns a number (about 7.8), but NSolve gives the following errors:

enter image description here

How can I take care of these?

$\endgroup$
1
$\begingroup$

Try

NMinimize[{q, g[q] >= 1, 5 < q < 15}, q, AccuracyGoal -> 3]
(* {9.95406, {q -> 9.95406}} *)

Here an alternativ workaround:

Normal[Plot[g[q], {q, 0, 20}, MaxRecursion -> 3,MeshFunctions -> {#2 &}, Mesh -> {{1}},MeshStyle -> {PointSize[Large]}]] /.Point[x_] :> {Point[x], Text[Style[x, 14]], Offset[{-20, 10}, x]}

enter image description here

$\endgroup$
  • $\begingroup$ Do you also get a slew of "not a number" and "stiff system expected" errors before Mathematica gives you this plot? Copying your code I indeed get this plot but all the errors that come before the output would make me suspicious. Same for the NMinimize approach, code is taking forever to evaluate and generates lots of errors before giving output. $\endgroup$ – tbfr416 Dec 5 '18 at 10:12
  • $\begingroup$ No I get no errors (version 11.0.1. Windows 64). The calculation NMInimize lasts some time... $\endgroup$ – Ulrich Neumann Dec 5 '18 at 10:16
  • $\begingroup$ Note that g is only meaningfully defined if q is given a value, so restrict it via g[q_?NumericQ] := MinValue[{(1/f[q, 0.2][p]), 10 > p > 0.1}, p] Then FindRoot[g[q] == 1, {q, 10}] gives a root. $\endgroup$ – KraZug Dec 5 '18 at 10:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.