as "x=4". This means that the result of nsolve() can be used in further calculations without parsing the
number from the expression. Further, nsolve() is usually faster than solve().
The function format is
nsolve(
equation,VarOrGuess
)
where equation is the equation to be solved, and VarOrGuess specifies the variable for which to solve,
and, optionally, a guess of the solution. As described in the manual, the command can be further
modfied with solution bounds like this:
nsolve(
equation,VarOrGuess
)|
bounds
where bounds is a conditional expression that specifies an interval over which to search for an answer.
See the manual for examples.
Like any numeric solver, nsolve() can be faster if you supply a guess or bound the solution interval.
Note that the guess need not a simple number, but can be a function itself.
With some functions, you must supply bounds to get the right solution. Consider y = x
2
as a simple
example. If y = 4, then there are two solutions, x = 2 and x = -2. Since both are correct, and nsolve()
cannot 'know' which solution you want, you need to supply the bound like this:
nsolve(x^2=4,x)|x>0 to find the x = 2 root
or
nsolve(x^2=4,x)|x<0 to find the x = -2 root.
To test the performance of the numeric solver, I found an estimating polynomial for the gamma function
over the range x = [1.5, 2.5]. The function is
f
(
x
)
= a + bx + cx
2
+ dx
3
+ ex
4
+ fx
5
+ gx
6
+ hx
7
+ ix
8
This graph shows the function approximation.
11 - 5