x2 = 1.1085 5630 2169 9
x3 = 2.1404 2730 947
and we want to find x3. Various permutations of the constraints give these results:
x>2 and x<2.2 x3 returned
2<x and x<2.2 x3 returned
x>low and x<high x3 returned
low<x and x<high x1 returned - incorrect!
low<x and high>x x1 returned - incorrect!
x>low and high>x x3 returned
If the constraints are numbers, then the conditional ordering is immaterial; nSolve() returned the correct
bounded root. However, if the constraints are local variables, then we must order the conditional
expression such that the independent variable occurs first.
solve() gives similar interesting results:
x>2 and x<2.2 x3 returned
2<x and x<2.2 x3 returned
x>low and x<high x3 returned
low<x and x<high undef<0 and x = x2 or undef<0 and x = x1 or x = x3
(long solution time, also warning More solutions may exist)
low<x and high>x undef<0 and x = x2 or undef<0 and x = x1 or x = x3
(even longer solution time, and warning More solutions may exist)
x>low and high>x x3 returned
Indpendent variable local declaration
In what may be a related situation, nSolve() results seem to depend on whether or not the independent
variable is declared local. I will use this program as an example:
solvebug(vf)
Func
©Demonstrate nSolve() failure with constraints
©29dec01/dburkett@infinet.com
Local vfs,tapx,t
© Find estimate tapx for solution
ln(1000*(vf-.015))→vfs
polyeval({3.618919682914,⁻31.003830334444,76.737472978603,⁻68.237201523917,262.4613974175
1,84.916629306139},vfs)+polyeval({⁻3.9287348339733⁻7,5.9179552041553⁻5,⁻0.0036896155610
467,0.12308990642018,⁻2.7560332337098,0},1/vfs)→tapx
© Find solution, with bounds from tapx
nSolve(vfts120(t)=vf,t)|t≥tapx-.4 and t≤min({tapx+.4,705.47})
EndFunc
and vfts120() looks like this:
vfts120(ts)
func
© This expression is all one program line.
polyeval({6.177102005557⁻14,⁻3.724921779392⁻11,9.3224938547231⁻9,⁻1.239459227407⁻6,
11 - 12