1
$\begingroup$

I have two functions $ f(n) = 1/(1+n) + b, (n \geq 0,b \geq 0) $ and $ g(n) = pn^2 + qn + r $. Assuming that I know the value of $ p, q $, and $ r $, I am trying to find a value for the constant $ b $ such that $ f(n) $ and $ g(n) $ intersect at most one point while keeping the shortest distance between the functions as small as possible. (I am trying to find a tight upper bound on a parabola in the first quadrant.)

Currently, I am starting with a large value of $ b $ and iteratively decreasing it by a small amount until Solve[f(n) == g(n), {n}] returns one or zero solutions. Can you please suggest an efficient way to do this?

Please find the code below.

ClearAll["Global`*"]
testFun = 1/(1 + Subscript[n, 1]) + b; 
g = 2.23 - 0.32*Subscript[n, 1] - 0.2*Subscript[n, 1]^2
For[bNum = 10, bNum >= 0, bNum -= 0.2, 
    numSol = Length[Solve[(testFun /. {b -> bNum}) == g && Subscript[n, 1] >= 0, {Subscript[n, 1]}]]; 
    p = Plot[{testFun /. {b -> bNum}, g}, {Subscript[n, 1], 0, 100}, PlotRange -> {0, 15}];
    Print[numSol]; 
    Print[p]; 
    If[numSol >= 1, Break[]]]; 
bNum = If[numSol == 1, bNum, bNum + 0.2]
$\endgroup$
  • $\begingroup$ Code that can be copied and run often helps attract users who could help you. $\endgroup$ – Michael E2 Dec 9 '18 at 0:39
  • $\begingroup$ @MichaelE2, thank you for the suggestion. I have added the code. $\endgroup$ – gaganso Dec 9 '18 at 1:02

Your Answer

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

Browse other questions tagged or ask your own question.