/* -*- c++ -*- ---------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator http://lammps.sandia.gov, Sandia National Laboratories Steve Plimpton, sjplimp@sandia.gov Copyright (2003) Sandia Corporation. Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains certain rights in this software. This software is distributed under the GNU General Public License. See the README file in the top-level LAMMPS directory. ------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- Contributing author: Pieter J. in 't Veld (SNL) ------------------------------------------------------------------------- */ #ifndef LMP_MATH_VECTOR_H #define LMP_MATH_VECTOR_H #include #include #define VECTOR_NULL {0, 0, 0} #define SHAPE_NULL {0, 0, 0, 0, 0, 0} #define FORM_NULL {0, 0, 0, 0, 0, 0} #define MATRIX_NULL {VECTOR_NULL, VECTOR_NULL, VECTOR_NULL} #define VECTOR4_NULL {0, 0, 0, 0} #define QUATERNION_NULL {0, 0, 0, 0} #define FORM4_NULL {0, 0, 0, 0, 0, 0, 0, 0, 0, 0} #define FZERO 1e-15 #define fzero(x) (((x)>-FZERO) && ((x)1) xtx[4] = xtx[2]; if (!form_inv(xtx_inv, xtx)) return 0; memcpy(eqn, xty, sizeof(vector)); form_vec_dot(eqn, xtx_inv); return 1; } // cubic regression: y = eqn[0] + eqn[1]*x + eqn[2]*x*x + eqn[3]*x*x*x inline int regress3(vector4 &eqn, int order, double *x, double *y, int n) { form4 xtx = FORM4_NULL, xtx_inv; vector4 xty = VECTOR4_NULL; double xn, xi, yi; int i; vec4_null(eqn); xtx[0] = n; if ((order = order%3)<0) order = -order; // max: cubic regress if (order<1) xtx[1] = 1.0; if (order<2) xtx[2] = 1.0; if (order<3) xtx[3] = 1.0; for (i=0; i1) xtx[8] = xtx[1]; if (order>2) { xtx[6] = xtx[7]; xtx[5] = xtx[2]; } if (!form4_inv(xtx_inv, xtx)) return 0; memcpy(eqn, xty, sizeof(vector4)); form4_vec4_dot(eqn, xtx_inv); return 1; } } #endif