XLPack 7.0
XLPack Numerical Library (C API) Reference Manual
Loading...
Searching...
No Matches

◆ sos()

void sos ( void(*)(int, double *, int, double *)  fnc,
int  n,
double  x[],
double  rtolx,
double  atolx,
double  tolf,
int  nprint,
int  maxiter,
int *  iter,
double  work[],
int  lwork,
int  iwork[],
int  liwork,
int *  info 
)

Solution of a system of nonlinear equations by Brown's method

Purpose
sos finds a zero of a system of n nonlinear functions in n variables
fi(x1, x2, ..., xn) = 0 (i = 1 to n)
by the Brown's method.

The algorithm is based on an iterative method which is a variation of Newton's method using Gaussian elimination in a manner similar to the Gauss-Seidel process. Convergence is roughly quadratic. The convergence behavior of this code is affected by the ordering of the equations, and it is advantageous to place linear and mildly nonlinear equations first in the ordering.

The user must provide a subroutine which calculates the function values. All partial derivatives required by the algorithm are approximated by first difference quotients.
Parameters
[in]fncUser supplied subroutine which calculates the functions fi(x) defined as follows.
void fnc(int n, double x[], int k, double *fval)
{
If k = 1, ..., n:
Return the k-th function value fk(x) at x[] in fval.
If k <= 0:
Print intermediate result (called only if nprint = 1). The estimated solution in x[] and its residual norm in fval on (-k)-th iteration will be provided.
}
x[] should not be changed.
[in]nNumber of functions and variables. (n > 0)
[in,out]x[]Array x[lx] (lx >= n)
[in] An initial estimate of the solution vector.
[out] The obtained solution vector.
[in]rtolxRelative error tolerance used in the convergence criteria. Each solution component x[i] is checked by an accuracy test of the form abs(x[i] - xold[i]) <= rtolx*abs(x[i]) + atolx, where xold[i] represents the previous iteration value. (rtolx >= 0)
[in]atolxAbsolute error tolerance used in the convergence criteria. If the user suspects some solution component may be zero, he should set atolx to an appropriate (depends on the scale of the remaining variables) positive value for better efficiency. (atolx >= 0)
[in]tolfResidual error tolerance used in the convergence criteria. Convergence will be indicated if all residuals (values of the functions or equations) are not bigger than tolf in magnitude. Note that extreme care must be given in assigning an appropriate value for tolf because this convergence test is dependent on the scaling of the equations. An inappropriate value can cause premature termination of the iteration process. (tolf >= 0)
[in]nprint= 0: Do not call fnc (k <= 0) to print out the intermediate solution.
= 1: Call fnc (k <= 0) to print out the intermediate solution on every iteration.
(For other values, nprint = 0 is assumed.)
[in]maxiterMaximum number of iterations. (maxiter >= 1)
[out]iterNumber of iterations required to converge.
[out]work[]Array work[lwork]
Work array.
On return, work[0] contains a norm of the residual.
[in]lworkThe length of work[]. (lwork >= 1 + 7*n + n*(n + 1)/2)
[out]iwork[]Array iwork[liwork]
Work array.
On return with info = 0, iwork[0] contains the sub-code.
= 1: Each component x(i) satisfies the error tolerance test: abs(x(i)-xold(i)) <= rtolx*abs(x(i)) + atolx.
= 2: All residuals are at most tolf in magnitude: abs(f(x,i)) <= tolf.
= 3: Both of above are satisfied.
= 4: Possibly converged (error tolerance too small or very slow convergence). (residual norms have remained roughly constant over several consecutive iterations)
[in]liworkThe length of iwork[]. (liwork >= n)
[out]info= 0: Successful exit (sub-code is set to iwork[0])
= -2: The argument n had an illegal value (n < 1)
= -4: The argument rtolx had an illegal value (rtolx < 0)
= -5: The argument atolx had an illegal value (atolx < 0)
= -6: The argument tolf had an illegal value (tolf < 0)
= -8: The argument maxiter had an illegal value (maxiter <= 0)
= -11: The argument lwork had an illegal value (lwork < 1+7*n+n*(n+1)/2)
= -13: The argument liwork had an illegal value (liwork < n)
= 1: Number of iterations has reached maxiter (maybe very slow convergence. Check if error tolerances are appropriate)
= 2: Number of iterations has reached maxiter (a local minimum may have been encountered or there may be limiting precision difficulties)
= 3: Iterative scheme appears to be diverging (residual norms have increased over several consecutive iterations)
= 4: A Jacobian-related matrix was singular
Reference
SLATEC