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_sys_func_easy (c05qb)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_roots_sys_func_easy (c05qb) is an easy-to-use function that finds a solution of a system of nonlinear equations by a modification of the Powell hybrid method.

Syntax

[x, fvec, user, ifail] = c05qb(fcn, x, 'n', n, 'xtol', xtol, 'user', user)
[x, fvec, user, ifail] = nag_roots_sys_func_easy(fcn, x, 'n', n, 'xtol', xtol, 'user', user)

Description

The system of equations is defined as:
fi x1,x2,,xn = 0 ,   ​ i= 1, 2, , n .  
nag_roots_sys_func_easy (c05qb) 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 fi at a point x.
[fvec, user, iflag] = fcn(n, x, user, iflag)

Input Parameters

1:     n int64int32nag_int scalar
n, the number of equations.
2:     xn – double array
The components of the point x at which the functions must be evaluated.
3:     user – Any MATLAB object
fcn is called from nag_roots_sys_func_easy (c05qb) with the object supplied to nag_roots_sys_func_easy (c05qb).
4:     iflag int64int32nag_int scalar
iflag>0 .

Output Parameters

1:     fvecn – double array
The function values fix .
2:     user – Any MATLAB object
3:     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.
2:     xn – double array
An initial guess at the solution vector.

Optional Input Parameters

1:     n int64int32nag_int scalar
Default: the dimension of the array x.
n, the number of equations.
Constraint: n>0 .
2:     xtol – double scalar
Suggested value: ε, where ε is the machine precision returned by nag_machine_precision (x02aj).
Default: machine precision
The accuracy in x to which the solution is required.
Constraint: xtol0.0 .
3:     user – Any MATLAB object
user is not used by nag_roots_sys_func_easy (c05qb), but is passed to fcn. Note that for large objects it may be more efficient to use a global variable which is accessible from the m-files than to use user.

Output Parameters

1:     xn – double array
The final estimate of the solution vector.
2:     fvecn – double array
The function values at the final point returned in x.
3:     user – Any MATLAB object
4:     ifail int64int32nag_int scalar
ifail=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=2
There have been at least 200 × n+1  calls to fcn. Consider restarting the calculation from the point held in x.
W  ifail=3
No further improvement in the solution is possible.
W  ifail=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 Accuracy). Otherwise, rerunning nag_roots_sys_func_easy (c05qb) from a different starting point may avoid the region of difficulty.
W  ifail=5
iflag was set negative in fcn.
   ifail=11
Constraint: n>0.
   ifail=12
Constraint: xtol0.0.
   ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   ifail=-999
Dynamic memory allocation failed.

Accuracy

If x^  is the true solution, nag_roots_sys_func_easy (c05qb) tries to ensure that
x-x^ 2 xtol × x^ 2 .  
If this condition is satisfied with xtol = 10-k , then the larger components of x have k significant decimal digits. There is a danger that the smaller components of x may have large relative errors, but the fast rate of convergence of nag_roots_sys_func_easy (c05qb) 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=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 convergence test assumes that the functions are reasonably well behaved. If this condition is not satisfied, then nag_roots_sys_func_easy (c05qb) may incorrectly indicate convergence. The validity of the answer can be checked, for example, by rerunning nag_roots_sys_func_easy (c05qb) with a lower value for xtol.

Further Comments

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

Example

This example determines the values x1 , , x9  which satisfy the tridiagonal equations:
3-2x1x1-2x2 = -1, -xi-1+3-2xixi-2xi+1 = -1,  i=2,3,,8 -x8+3-2x9x9 = -1.  
function c05qb_example


fprintf('c05qb example results\n\n');

% The following starting values provide a rough solution.
x = -ones(9, 1);
[xOut, fvec, user, ifail] = c05qb(@fcn, x);
switch ifail
  case {0}
    fprintf('\nFinal 2-norm of the residuals = %12.4e\n', norm(fvec));
    fprintf('\nFinal approximate solution\n');
    disp(xOut);
  case {2, 3, 4}
    fprintf('\nApproximate solution\n');
    disp(xOut);
end



function [fvec, user, iflag] = fcn(n, x, user, iflag)
  fvec = zeros(n, 1);
  fvec(1:n) = (3.0-2.0.*x).*x + 1.0;
  fvec(2:n) = fvec(2:n) - x(1:(n-1));
  fvec(1:(n-1)) = fvec(1:(n-1)) - 2.0.*x(2:n);
c05qb example results


Final 2-norm of the residuals =   1.1926e-08

Final approximate solution
   -0.5707
   -0.6816
   -0.7017
   -0.7042
   -0.7014
   -0.6919
   -0.6658
   -0.5960
   -0.4164


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–2015