The NEWTON function solves a system of *n* non-linear equations in *n* dimensions using a globally-convergent Newton’s method.

NEWTON is based on the routine newt described in section 9.7 of *Numerical Recipes in C: The Art of Scientific Computing* (Second Edition), published by Cambridge University Press, and is used by permission.

## Examples

Use NEWTON to solve an *n*-dimensional system of *n* non-linear equations. Systems of non-linear equations may have multiple solutions; starting the algorithms with different initial guesses enables detection of different solutions.

FUNCTION newtfunc, X

RETURN, [X[0] + X[1] - 3, X[0]^2 + X[1]^2 - 9]

END

PRO TEST_NEWTON

; Provide an initial guess as the algorithm's starting point:

X = [1d, 5d]

; Compute the solution:

result = NEWTON(X, 'newtfunc')

; Print the result:

PRINT, 'For X=[1.0, 5.0], result = ', result

;Try a different starting point.

X = [1d, -1d]

; Compute the solution:

result = NEWTON(X,'newtfunc')

;Print the result.

PRINT, 'For X=[1.0, -1.0], result = ', result

END

TEST_NEWTON

IDL prints:

For X=[1.0, 5.0], result = -2.4871776e-006 3.0000025

For X=[1.0, -1.0], result = 3.0000000 -2.9985351e-008

## Syntax

*Result* = NEWTON( *X*, *Vecfunc* [, CHECK=*variable*] [, /DOUBLE] [, ITMAX=*value*] [, STEPMAX=*value*] [, TOLF=*value*] [, TOLMIN=*value*] [, TOLX=*value*] )

## Return Value

The result is an *n*-element vector containing the solution.

## Arguments

### X

An *n*-element vector containing an initial guess at the solution of the system.

**Note: **If NEWTON is complex then only the real part is used for the computation.

### Vecfunc

A scalar string specifying the name of a user-supplied IDL function that defines the system of non-linear equations. This function must accept an *n*-element vector argument *X* and return an *n*-element vector result.

For example, suppose the non-linear system is defined by the following equations:

*y*_{0} = *x*_{0} + *x*_{1} - 3, *y*_{1} = *x*_{0}^{2} + *x*_{1}^{2} - 9

We write a function NEWTFUNC to express these relationships in the IDL language:

`FUNCTION newtfunc, X`

RETURN, [X[0] + X[1] -3.0, X[0]^2 + X[1]^2 - 9.0]

`END`

## Keywords

### CHECK

NEWTON calls an internal function named fmin() to determine whether the routine has converged to a local minimum rather than to a global minimum (see *Numerical Recipes*, section 9.7). Use the CHECK keyword to specify a named variable which will be set to 1 if the routine has converged to a local minimum or to 0 if it has not. If the routine does converge to a local minimum, try restarting from a different initial guess to obtain the global minimum.

### DOUBLE

Set this keyword to force the computation to be done in double-precision arithmetic.

### ITMAX

The maximum allowed number of iterations. The default value is 200.

### STEPMAX

The scaled maximum step length allowed in line search. The default value is 100.0.

### TOLF

Set the convergence criterion on the function values. The default value is 1.0 x 10^{-4}.

### TOLMIN

Set the criterion for deciding whether spurious convergence to a minimum of the function fmin() has occurred. The default value is 1.0 x 10^{-6}.

### TOLX

Set the convergence criterion on *X*. The default value is 1.0 x 10^{-7}.

## Version History

4.0 |
Introduced |