The DataModeling Class


The DataModeling Class

Let us develop (or revisit ) the capability to compute a least squares fit to a collection of data according to Eq. (24.8) and Eq. (24.9). The least squares fit analysis process has three parts ”you decide which polynomial equation to use for the curve fit expression, you load the arrays A T A and A T y , and you solve the system of equations and return the polynomial coefficients.

The third part of the process is generic and can be implemented by a generic class. In Chapter 23 we defined the DataModeling class that contains the leastSquaresFit() method. The method takes three input arguments. A Polynomial equation is used to store information about the polynomial equation used for the data fit. The other two arguments are arrays used to store the data that will be fit.

The leastSquaresFit() method is simple. It only does three things. It first fills the A T A and A T y arrays calling the loadArrays() method on the Polynomial object. The least squares system of equations is then solved using the gaussian() method from the EqnSolver class. Finally, the polynomial coefficients are copied into a storage array using the setCoefficients() method.

The leastSquaresFit() method source code is shown next .

 public static void leastSquaresFit(Polynomial equation,                               double x[], double y[]) {   //  Load the AT*A and AT*b arrays using the data in   //  x[] and y[].   equation.loadArrays(x,y);   //  Solve the system of equations AT*A*c = AT*y   //  The b[] array is overwritten to contain the   //  curve fit coefficients.   EqnSolver.gaussian(equation.getA(),                      equation.getB());   //  Copy the curve fit coefficient values into   //  the Polynomial object's coeffs[] array.   equation.setCoefficients(equation.getB());  } 


Technical Java. Applications for Science and Engineering
Technical Java: Applications for Science and Engineering
ISBN: 0131018159
EAN: 2147483647
Year: 2003
Pages: 281
Authors: Grant Palmer

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net