# Java in Science: Data Inter- and Extrapolation Using Numerical Methods of Polynomial Fittings, Part 3

**Review Part 2**

#### Polynomial Fittings

Now that we have introduced concepts in *Linear Algebra*, it is time we apply
it to a category of numerical analysis known as ** Polynomial Fittings**.
In the purpose of determining the behavior of a function, as data pairs
[

*x*, y(

_{i}*x*) ] is severalfold. If we want to approximate other values of the function at values of

_{i}*x*not tabulated (

*interpolation*or

*extrapolation*) and to estimate the integral of

*f(x)*and its derivative,

*Polynomial Fittings*provides the capability of smoothing the data. Approximating unknown values of a function is straightforward. We will try to find a polynomial that fits a selected set of points [

*x*, y(

_{i}*x*) ] and assume that the polynomial and the function behave nearly the same over the interval in question. Values of the polynomial then should be reasonable estimates of the unknown function. There are problems with interpolating polynomials when data are not smooth, meaning there are local irregularities. In such cases polynomial of higher order would be required to follow the irregularities, but such polynomials, while fitting to the irregularity, deviate widely at other regions where the function is smooth. An interpolating polynomial, although passing through the points used in its construction, does not in general give exactly correct values when used for interpolation, and this leads to error of approximation.

_{i}#### Java Codes

##### Polyfit Class

This class has one constructor that instantiates a Polyfit object. The constructor takes two input argument arrays with an integer to specify the polynomial order to fit data into. All instance variables are private and all instance methods are accessor. The code is descriptive as much as possible for the non-expert reader.

//result = R^{-1}* ( Q^{T}* _y^{T})

##### Polyval Class

//youtMatrix = (youtMatrix .* _xMatrix) + pC

//Rinv = R^{-1}

//E = V * R^{-1}

//e = sqrt(matOnes + E.*E)

//SumT = (sum((E.*E)^{T}))^{T}

//e = sqrt(matOnes + SumT)

We will conclude by running the complete program in Part 4.

Download ** Jama** and

**and**

*Jamlab***.**

*Jamlab documentation*#### References

*Java for Engineers and Scientists*by Stephen J. Chapman, Prentice Hall, 1999.*Introductory Java for Scientists and Engineers*by Richard J. Davies, Addison-Wesley Pub. Co., 1999.*Applied Numerical Analysis (Sixth Edition)*by Curtis F. Gerald and Patrick O. Wheatly, Addison-Wesley Pub. Co., 1999.*Linear Algebra and Its Applications (Second Edition)*, by David C. Lay, Addison-Wesley Pub. Co.*Numerical Recipes in Fortran 77, the Art of Scientific Computing (Volume 1)*by William H. Press, Saul A. Teukolsky, William T. Vetterling, and Brian P. Flannery, Cambridge University Press, 1997.*Mastering MATLAB 5: A Comprehensive Tutorial and Reference*by Duane Hanselman and Bruce Littlefield, Prentice Hall, 1997.*Advanced Mathematics and Mechanics Applications using MATLAB*by Louis H. Turcotte and Howard B. Wilson, CRC Press, 1998.

#### Related Articles

- Java as a Scientific Programming Language (Part 1): More Issues for Scientific Programming in Java
- Scientific Computing in Java (Part 2): Writing Scientific Programs in Java
- Using Java in Scientific Research: An Introduction

#### About the Author

*Sione Palu is a Java developer at Datacom in Auckland, New Zealand, currently involved in a Web application development project. Palu graduated from the University of Auckland, New Zealand, double majoring in mathematics and computer science. He has a personal interest in applying Java and mathematics in the fields of mathematical modeling and simulations, expert systems, neural and soft computation, wavelets, digital signal processing, and control systems.*

*
*