hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_roots_withdraw_sys_func_easy (c05nb)

Purpose

nag_roots_withdraw_sys_func_easy (c05nb) is an easy-to-use function that finds a solution of a system of nonlinear equations by a modification of the Powell hybrid method.
Note: this function is scheduled to be withdrawn, please see c05nb in Advice on Replacement Calls for Withdrawn/Superseded Routines..

Syntax

[x, fvec, ifail] = c05nb(fcn, x, 'n', n, 'xtol', xtol)
[x, fvec, ifail] = nag_roots_withdraw_sys_func_easy(fcn, x, 'n', n, 'xtol', xtol)

Description

The system of equations is defined as:
fi (x1,x2,,xn) = 0 ,   for ​ i = 1, 2, , n .
fi (x1,x2,,xn) = 0 ,   for ​ i= 1, 2, , n .
nag_roots_withdraw_sys_func_easy (c05nb) is based on the MINPACK routine HYBRD1 (see Moré et al. (1980)). It chooses the correction at each step as a convex combination of the Newton and scaled gradient directions. The Jacobian is updated by the rank-1 method of Broyden. At the starting point, the Jacobian is approximated by forward differences, but these are not used again until the rank-1 method fails to produce satisfactory progress. For more details see Powell (1970).

References

Moré J J, Garbow B S and Hillstrom K E (1980) User guide for MINPACK-1 Technical Report ANL-80-74 Argonne National Laboratory
Powell M J D (1970) A hybrid method for nonlinear algebraic equations Numerical Methods for Nonlinear Algebraic Equations (ed P Rabinowitz) Gordon and Breach

Parameters

Compulsory Input Parameters

1:     fcn – function handle or string containing name of m-file
fcn must return the values of the functions fifi at a point xx.
[fvec, iflag] = fcn(n, x, iflag)

Input Parameters

1:     n – int64int32nag_int scalar
nn, the number of equations.
2:     x(n) – double array
The components of the point xx at which the functions must be evaluated.
3:     iflag – int64int32nag_int scalar
iflag > 0 iflag>0 .

Output Parameters

1:     fvec(n) – double array
The function values fi(x) fi(x) .
2:     iflag – int64int32nag_int scalar
In general, iflag should not be reset by fcn. If, however, you wish to terminate execution (perhaps because some illegal point x has been reached), then iflag should be set to a negative integer. This value will be returned through ifail.
2:     x(n) – double array
n, the dimension of the array, must satisfy the constraint n > 0 n>0 .
An initial guess at the solution vector.

Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The dimension of the array x.
nn, the number of equations.
Constraint: n > 0 n>0 .
2:     xtol – double scalar
The accuracy in x to which the solution is required.
Suggested value: sqrt(ε)ε, where εε is the machine precision returned by nag_machine_precision (x02aj).
Default: sqrt(machine precision) machine precision
Constraint: xtol0.0 xtol0.0 .

Input Parameters Omitted from the MATLAB Interface

wa lwa

Output Parameters

1:     x(n) – double array
The final estimate of the solution vector.
2:     fvec(n) – double array
The function values at the final point returned in x.
3:     ifail – int64int32nag_int scalar
ifail = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Errors or warnings detected by the function:

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

W ifail < 0ifail<0
You have set iflag negative in fcn. The value of ifail will be the same as your setting of iflag.
  ifail = 1ifail=1
On entry, n0 n0 ,
or xtol < 0.0 xtol<0.0 .
W ifail = 2ifail=2
There have been at least 200 × (n + 1) 200 × (n+1)  evaluations of fcn. Consider restarting the calculation from the final point held in x.
W ifail = 3ifail=3
No further improvement in the approximate solution x is possible; xtol is too small.
  ifail = 4ifail=4
The iteration is not making good progress. This failure exit may indicate that the system does not have a zero, or that the solution is very close to the origin (see Section [Accuracy]). Otherwise, rerunning nag_roots_withdraw_sys_func_easy (c05nb) from a different starting point may avoid the region of difficulty.
  ifail = 999ifail=-999
Internal memory allocation failed.

Accuracy

If x^  is the true solution, nag_roots_withdraw_sys_func_easy (c05nb) tries to ensure that
x xtol × .
x-x^ xtol × x^ .
If this condition is satisfied with xtol = 10k xtol = 10-k , then the larger components of xx have kk significant decimal digits. There is a danger that the smaller components of xx may have large relative errors, but the fast rate of convergence of nag_roots_withdraw_sys_func_easy (c05nb) usually obviates this possibility.
If xtol is less than machine precision and the above test is satisfied with the machine precision in place of xtol, then the function exits with ifail = 3ifail=3.
Note:  this convergence test is based purely on relative error, and may not indicate convergence if the solution is very close to the origin.
The test assumes that the functions are reasonably well behaved. If this condition is not satisfied, then nag_roots_withdraw_sys_func_easy (c05nb) may incorrectly indicate convergence. The validity of the answer can be checked, for example, by rerunning nag_roots_withdraw_sys_func_easy (c05nb) with a lower value for xtol.

Further Comments

Local workspace arrays of fixed lengths are allocated internally by nag_roots_withdraw_sys_func_easy (c05nb). The total size of these arrays amounts to n × (3 × n + 13) / 2 n×(3×n+13)/2 double elements.
The time required by nag_roots_withdraw_sys_func_easy (c05nb) to solve a given problem depends on nn, the behaviour of the functions, the accuracy requested and the starting point. The number of arithmetic operations executed by nag_roots_withdraw_sys_func_easy (c05nb) to process each call of fcn is about 11.5 × n2 11.5×n2 . Unless fcn can be evaluated quickly, the timing of nag_roots_withdraw_sys_func_easy (c05nb) will be strongly influenced by the time spent in fcn.
Ideally the problem should be scaled so that, at the solution, the function values are of comparable magnitude.

Example

function nag_roots_withdraw_sys_func_easy_example
x = [-1;
     -1;
     -1;
     -1;
     -1;
     -1;
     -1;
     -1;
     -1];
[xOut, fvec, ifail] = nag_roots_withdraw_sys_func_easy(@fcn, x)

function [fvec, iflag] = fcn(n,x,iflag)
  fvec = zeros(n, 1);
  for k = 1:double(n)
    fvec(k) = (3.0-2.0*x(k))*x(k)+1.0;
    if k > 1
      fvec(k) = fvec(k) - x(k-1);
    end
    if k < n
      fvec(k) = fvec(k) - 2*x(k+1);
    end
  end
 

xOut =

   -0.5707
   -0.6816
   -0.7017
   -0.7042
   -0.7014
   -0.6919
   -0.6658
   -0.5960
   -0.4164


fvec =

   1.0e-08 *

    0.6560
   -0.4175
   -0.5193
   -0.2396
    0.2022
    0.4818
    0.2579
   -0.3884
   -0.0136


ifail =

                    0


function c05nb_example
x = [-1;
     -1;
     -1;
     -1;
     -1;
     -1;
     -1;
     -1;
     -1];
[xOut, fvec, ifail] = c05nb(@fcn, x)

function [fvec, iflag] = fcn(n,x,iflag)
  fvec = zeros(n, 1);
  for k = 1:double(n)
    fvec(k) = (3.0-2.0*x(k))*x(k)+1.0;
    if k > 1
      fvec(k) = fvec(k) - x(k-1);
    end
    if k < n
      fvec(k) = fvec(k) - 2*x(k+1);
    end
  end
 

xOut =

   -0.5707
   -0.6816
   -0.7017
   -0.7042
   -0.7014
   -0.6919
   -0.6658
   -0.5960
   -0.4164


fvec =

   1.0e-08 *

    0.6560
   -0.4175
   -0.5193
   -0.2396
    0.2022
    0.4818
    0.2579
   -0.3884
   -0.0136


ifail =

                    0



PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013