1

When trying to answer this question I've discovered what looks like a bug in NSolve introduced in version 11.1.0.

$Version
"11.1.0 for Microsoft Windows (64-bit) (March 13, 2017)"

With setup

Clear[dBeta, solnEquation, solnFun];

dBeta[k_Integer, x_, var1_] = Derivative[k, 0][Beta[#1, #2, 2] &][x, var1];
solnEquation[var1_, var2_, x_] = Sum[Binomial[5, k]*dBeta[k, x, var1]*var2^k, {k, 0, 5}];
equation[var1_, var2_, x_] := solnEquation[var1, var2, x] == Beta[2, 2];

Solve is able to find two solutions for var1 = 2, var2 = 1/10:

sol = Solve[equation[2, 1/10, x] && 0 < x < 1, x, Reals];
equation[2, 1/10, x] /. Normal@sol // N    

Solve::incs: Warning: Solve was unable to prove that the solution set found is complete.

{True, True}

While NSolve claims that there are no solutions in the real domain:

NSolve[equation[2, 1/10, x] && 0 < x < 1, x, Reals]
{}

But without this restriction it finds two solutions in the real domain:

NSolve[equation[2, 1/10, x] && 0 < x < 1, x]
equation[2, 1/10, x] /. %    
{{x -> 0.328152}, {x -> 0.741041}}

{True, True}

In version 11.0.1 NSolve gives correct answer for the real domain:

$Version
"11.0.1 for Microsoft Windows (64-bit) (September 20, 2016)"
NSolve[equation[2, 1/10, x] && 0 < x < 1, x, Reals]
{{x -> 0.3281517106189123`}, {x -> 0.7410414526199698`}}

Is it a bug in version 11.1.0?

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Alexey Popkov
  • 61,809
  • 7
  • 149
  • 368

2 Answers2

2

A possible cure for your problem is to use FunctionExpand[] to ensure that the incomplete beta function is expanded to the actual polynomial it represents. Thus:

NSolve[FunctionExpand[equation[2, 1/10, x]] && 0 < x < 1, x, Reals]
   {{x -> 0.3281517106189123}, {x -> 0.7410414526199698}}
J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
1

This is a precision issue

$Version

(* "12.0.0 for Mac OS X x86 (64-bit) (April 7, 2019)" *)

Clear[dBeta, solnEquation, solnFun];

dBeta[k_Integer, x_, var1_] = Derivative[k, 0][Beta[#1, #2, 2] &][x, var1];
solnEquation[var1_, var2_, x_] = 
  Sum[Binomial[5, k]*dBeta[k, x, var1]*var2^k, {k, 0, 5}];
equation[var1_, var2_, x_] := solnEquation[var1, var2, x] == Beta[2, 2];

sol = Solve[equation[2, 1/10, x] && 0 < x < 1, x, Reals];

Note that using machine precision the imaginary parts are only approximately zero.

sol // N

(* {{x -> ConditionalExpression[0.328152 + 0. I, 
    0.0420629 + 0. I ∈ Reals]}, {x -> 
   ConditionalExpression[0.741041 + 0. I, 0.138925 + 0. I ∈ Reals]}} *)

The solutions are exact

equation[2, 1/10, x] /. sol // FullSimplify

(* {True, True} *)

However, when using NSolve for this problem you cannot use machine precision. Use arbirary-precision by specifying the WorkingPrecision

NSolve[equation[2, 1/10, x] && 0 < x < 1, x, Reals, 
 WorkingPrecision -> 15]

(* {{x -> 0.328151710618912}, {x -> 0.741041452619970}} *)

EDIT: Alternatively, since 0 < x < 1implies thatx` is real just use

NSolve[equation[2, 1/10, x] && 0 < x < 1, x]

(* {{x -> 0.328152}, {x -> 0.741041}} *)
Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198