13 Root finding

13.1 Overview

To provide a uniformed framework to root finding functions, we use several structures for storing different kind of functions. The pointer params is used to store the extra parameters. These new types come with dedicated macros starting in PNL_EVAL to evaluate the function and their Jacobian.

/* 
 * f: R --> R 
 * The function  pointer returns f(x) 
 * 
typedef struct { 
  double (*F) (double x, void *params); 
  void *params; 
} PnlFunc ; 
#define PNL_EVAL_FUNC(Fstruct, x) (*((Fstruct)->F))(x, (Fstruct)->params)
/* 
 * f: R^2 --> R 
 * The function pointer returns f(x) 
 * 
typedef struct { 
  double (*F) (double x, double y, void *params); 
  void *params; 
} PnlFunc2D ; 
#define PNL_EVAL_FUNC2D(Fstruct, x, y) (*((Fstruct)->F))(x, y, (Fstruct)->params)
/* 
 * f: R --> R 
 * The function pointer computes f(x) and Df(x) and stores them in fx 
 * and dfx respectively 
 * 
typedef struct { 
  void (*F) (double x, double *fx, double *dfx, void *params); 
  void *params; 
} PnlFuncDFunc ; 
#define PNL_EVAL_FUNC_FDF(Fstruct, x, fx, dfx) (*((Fstruct)->F))(x, fx, dfx, (Fstruct)->params)
/* 
 * f: R^n --> R 
 * The function pointer returns f(x) 
 * 
typedef struct { 
  double (*F) (const PnlVect *x, void *params); 
  void *params; 
} PnlRnFuncR ; 
#define PNL_EVAL_RNFUNCR(Fstruct, x) (*((Fstruct)->F))(x, (Fstruct)->params)
/* 
 * f: R^n --> R^m 
 * The function pointer computes the vector f(x) and stores it in 
 * fx (vector of size m) 
 * 
typedef struct { 
  void (*F) (const PnlVect *x, PnlVect *fx, void *params); 
  void *params; 
} PnlRnFuncRm ; 
#define PNL_EVAL_RNFUNCRM(Fstruct, x, fx) (*((Fstruct)->F))(x, fx, (Fstruct)->params) 
 
/* 
 * Synonymous of PnlRnFuncRm for f:R^n --> R^n 
 * 
typedef PnlRnFuncRm PnlRnFuncRn; 
#define PNL_EVAL_RNFUNCRN  PNL_EVAL_RNFUNCRM
/* 
 * f: R^n --> R^m 
 * The function pointer computes the vector f(x) and stores it in fx 
 * (vector of size m) 
 * The Dfunction pointer computes the matrix Df(x) and stores it in dfx 
 * (matrix of size m x n) 
 * 
typedef struct { 
  void (*F) (const PnlVect *x, PnlVect *fx, void *params); 
  void (*DF) (const PnlVect *x, PnlMat *dfx, void *params); 
  void (*FDF) (const PnlVect *x, PnlVect *fx, PnlMat *dfx, void *params); 
  void *params; 
} PnlRnFuncRmDFunc ; 
#define PNL_EVAL_RNFUNCRM_DF(Fstruct, x, dfx) \ 
    (*((Fstruct)->Dfunction))(x, dfx, (Fstruct)->params) 
#define PNL_EVAL_RNFUNCRM_FDF(Fstruct, x, fx, dfx) \ 
    (*((Fstruct)->F))(x, fx, dfx, (Fstruct)->params) 
#define PNL_EVAL_RNFUNCRM_F_DF(Fstruct, x, fx, dfx)    \ 
      if ( (Fstruct)->FDF != NULL )                    \ 
        {                                              \ 
          PNL_EVAL_RNFUNCRN_FDF (Fstruct, x, fx, dfx); \ 
        }                                              \ 
      else                                             \ 
        {                                              \ 
          PNL_EVAL_RNFUNCRN (Fstruct, x, fx);          \ 
          PNL_EVAL_RNFUNCRN_DF (Fstruct, x, dfx);      \ 
        } 
/* 
 * Synonymous of PnlRnFuncRmDFunc for f:R^n --> R^m 
 * 
typedef PnlRnFuncRmDFunc PnlRnFuncRnDFunc; 
#define PNL_EVAL_RNFUNCRN_DF PNL_EVAL_RNFUNCRM_DF 
#define PNL_EVAL_RNFUNCRN_FDF PNL_EVAL_RNFUNCRM_FDF 
#define PNL_EVAL_RNFUNCRN_F_DF PNL_EVAL_RNFUNCRM_F_DF

13.2 Functions

To use the following functions, you should include pnl/pnl_root.h.

Real valued functions of a real argument

Vector valued functions with several arguments

We provide two wrappers for calling minpack routines.