15 for (
unsigned long i=0; i<n; i++) J_[i] =
new double[n];
17 delx_ =
new double[n];
40 for (
unsigned long i=0; i<n_; i++)
delete [] J_[i];
46void OdeNewton::err (
double *errx,
double *errf) {
48 double tx, tf, mx = 0, my = 0;
50 for (
unsigned long i=0; i<n_; i++) {
51 if ( (tx = fabs(delx_[i])) > mx ) mx = tx;
52 if ( (tf = fabs(f_[i])) > my ) my = tf;
58void OdeNewton::JLU (
double *x) {
68void OdeNewton::solve_LU_(
double **LU,
int *p,
double *b,
int n,
double *out) {
73int OdeNewton::check_integrity (
double *x) {
75 for (
unsigned long i=0; i<n_; i++) {
77 if ( std::isnan(x[i]) )
return(2);
79 if ( !std::isfinite(x[i]) )
return(3);
86 unsigned long i, iter;
91 for (i=0; i<n_; i++) delx_[i] = INFINITY;
96 if ( modified_ && (!ignore_JLU_) ) JLU(x);
100 while ( (errx > tol_Newton_) || (errf > tol_Newton_) ) {
102 if ( (!ignore_JLU_) && (!modified_) && (iter % iJLU_ == 0) ) JLU(x);
106 for (i=0; i<n_; i++) f_[i] = -f_[i];
108 solve_LU_(J_, p_, f_, n_, delx_);
110 for (i=0; i<n_; i++) x[i] += delx_[i];
116 if ( iter > iter_Newton_ )
return(1);
118 if ( iter % icheck_ == 0 ) {
119 suc = check_integrity(x);
120 if ( suc != 0 )
return(suc);
virtual void J_Newton(double *x, double **J)=0
evaluates the Jacobian matrix of the function being zeroed
int solve_Newton(double *x)
Solve the system of equations.
OdeNewton(unsigned long n)
constructs
virtual ~OdeNewton()
destructs
virtual void f_Newton(double *x, double *f)=0
evaluates the function being zeroed
void ode_solve_LU(double **LU, int *p, double *b, int n, double *out)
Solves a matrix equation where the matrix has already be crout LU decomposed.
void ode_crout_LU(double **A, int n, int *p)
Crout LU decomposition.