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

#### Running the Complete Program

Here is the complete program. Please review the lessons of Parts 1 through 3 before using it.

#### Interpolations

Intermediate values between data-pairs can be estimated for any polynomial order by
evaluating the specific polynomial in the domain boundry with a large number of points.
The data pairs used in this tutorial were :

double[] **xVal = {-8.,-6.,-4.,-2.,0.,2.,4.,6.,8.,10.,12.}**;

double[] **yVal = {-4.,-7.,-2.,1.,2.,1.5,4.,5.,4.9,6.7,9.}**;

There were two thousand points between the minimum , **-8.** and the maximum,
**12**, to make the estimation as smooth as possible.

The following graphs show different plottings for different order of best fit polynomials.

** blue line** - actual data pairs

**- best fit polynomial**

*red line***- upper bound error estimate**

*black line***- lower bound error estimate**

*yellow line***Y = 1.918182**

**Y = 0.684091*X + 0.55**

**Y = 0.010111*X**

^{2}+ 0.724534*X + 0.913986**Y = 0.000874*X**

^{3}- 0.015355*X^{2}+ 0.672786*X + 1.031469**Y = 0.000754*X**

^{4}- 0.005157*X^{3}- 0.072654*X^{2}+ 0.950233*X + 1.61049**Y = 0.000131*X**

^{5}+ 0.002061*X^{4}+ 0.006171*X^{3}- 0.161537*X^{2}+ 0.739704*X + 2.27972**Y = 0.000033*X**

^{6}- 0.000525*X^{5}- 0.000927*X^{4}+ 0.040596*X^{3}- 0.092734*X^{2}+ 0.172263*X + 2.004319**Y = 0.000004*X**

^{7}+ 0.000088*X^{6}- 0.000177*X^{5}- 0.006612*X^{4}+ 0.033296*X^{3}+ 0.049072*X^{2}+ 0.205033*X + 1.506746#### Extrapolations

Extending the estimation of the best fit polynomials to extrapolate outside the data pairs
domain gives wildly osscilated error-bounds. Error-bounds increase as the estimation moves
away from the *minimum = -8* or *maximum = 12* point of the data pairs domain.
Error-bounds would have reasonable values around the vicinity of the minimum and the maximum.

The following graphs plot the extrapolation beyond the data pairs domain extending from
*minimum = -8* to *maximum = 22*:

#### Applications

Polynomial fittings is one of the numerical techniques that engineers and scientists use
most often in estimation, simulation, and even model prediction. There
are other numerical methods for estimation, such as *splines* for example. The choice
depends on the domain of interest for the engineer. A NASA scientist
might prefer the *cubic spline* as an estimator, while a financial engineering
economist in the Tokyo stock market prefer to use a *polynomial fitting* of ORDER = 1,
(straight line) for future outcome predictions.

#### Final Word

We have introduced the concepts of *matrix algebra* in this tutorial and how it is
applied in numerical techniques of *polynomial fittings*. *Linear algebra* is
a cornerstone of today's scientific software. There are other branches of engineering
mathematics, such as *discrete mathematics*, *differential equations*,
*multi-variable calculus*, *statistics and probabilities*, *complex variables*,
and *operations research*, etc., which are also the foundations of scientific
software. I will try to visit some of these in future tutorials.

#### Book References

*Java for Engineers and Scientists*by*Stephen J. Chapman*, publisher :*PRENTICE HALL**Introductory Java for Scientists and Engineers*by*Richard J. Davies*, publisher :*ADDISON-WESLEY**Applied Numerical Analysis*(Sixth Edition), by*Curtis F. Gerald*and*Patrick O. Wheatly*, publisher :*ADDISON-WESLEY**Linear Algebra and its Applications*(Second Edition), by*David C. Lay*, publisher :*ADDISON-WESLEY**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*, publisher :*CAMBRIDGE UNIVERSITY PRESS**Mastering MATLAB 5*, by*Duane Hanselman*and*Bruce Littlefield*, publisher :*PRENTICE HALL**Advanced Mathematics and Mechanics Applications using MATLAB*by*Howard B. Wilson*, publisher :*CRC Press*

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.*

*
*

### Recommended Partner Resources