(Credit to Timité Hassan)
[11.11] exp
▶
▶▶
▶
list() fails with solve() in user functions
If entered from the command line, this expression
exp▶list(solve(x^2+x=0,x),x)
correctly returns the solutions {-1, 0} as a list. However, if you include this expression in a user
function, the empty list {} is returned instead of the correct solution list. The fix to this problem is to use
expr() to evaluate the expression as a string, as shown for example in this function:
t(xx,yy)
Func
expr("exp▶list(solve(xx,yy),"&string(yy)&")")
EndFunc
(Bug found by Michal Letowski; fix by Bhuvanesh Bhatt)
[11.12] nSolve() may ignore solution constraints
This tip demonstrates two cases for which nSolve() ignores solution constraints and returns a solution
outside of the constraints. The first case involves the ordering of the conditional constraint if it uses
local variables, and the second case relates to whether or not the independent variable is declared
local or not. AMS 2.05 is used for the examples, but earlier AMS versions may also exhibit the
problems.
Conditional constraint ordering
When used in a program or function, nSolve() does not always honor solution constraints if the
constraints are local variables. If the constraint is expressed like this:
...
local low,high
value_1→low
value_2 →high
nsolve(f(x)=0,x0|x>low and x<high →result
...
then nSolve() seems to return the correct root. However, if the constraint conditional expression is
reversed with respect to x, that is, low < x instead of x > low:
nsolve(f(x)=0,x0|low<x and x<high →result
then nSolve() may return a result that is a root, but is not bound by the constraints. As an example
consider the function
f
(
x
)
= x
3
− 6
$
x
2
+ 11
$
x − 6 + sin
(
x
)
with roots
x1 = 0.7137 9958 4872 36
11 - 11