GuidesJava in Science: Data Interpolation and Extrapolation Using Numerical Methods of Polynomial...

Java in Science: Data Interpolation and Extrapolation Using Numerical Methods of Polynomial Fittings, Part 1

Developer.com content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

The value of a function g(x) at a specific set of points x1,x2,x3,…,xn is sometimes known, but there is no analytical expression for g(x) that enables a calculation of its value at an arbitrary point. An estimation of g(x) for an arbitrary x in a way that drawing a smooth curve through (xi,g(xi)) can be achieved by numerical analysis.

As an example of looking at a sales profit (in millions of dollars) P = [3.4, 5.1, 7.6, 9] for every two month period T = [2, 4, 6, 8] from a manufacturing company, and when one is trying to estimate P where T = 5(inside T-boundary) or T = 10(outside T-boundary) it
would be inaccurate without data smoothing techniques of numerical analysis. If the desired x is bounded between [x1,…,xn] that is x is in between the largest and the smallest of the xi‘s, this is called
interpolation and if x is outside the boundaries then it is called extrapolation.

Polynomials

Interpolation and extrapolation techniques must model the function, within and beyond the boundaries, [x1,…,xn] by some functional form. The functional form that is going to be discussed in this tutorial is known as polynomial fittings. Polynomials of order n have the general form of:

y = anxn + a(n-1)x(n-1) + … + a2x2 + a1x + a0

n is an integern >= 0.an is a Real number.an is the coefficient of the nth term.Example of a 4th-order polynomial: y = -2x4 + 5x3 + 3x2 – 3x + 7 , thus polynomial coefficients are: a4 = -2, a3 = 5, a2 = 3, a1 = -3, a0 = 7

In this tutorial, we will define and derive mathematical operations mainly in matrix algebra for how to fit a polynomial of order n into a set of known or observed data pairs , [xi,yi]. A polynomial of any order is specified and then the coefficients are returned as an array of doubles (Java data-type).

Linear (straight-line) fitting is a polynomial of order 1 (also known as a first-order polynomial, and it has wide applications in modeling from simulations, graphics to financial forecast . Before we delve in to the Java coding , I want to introduce the concept of linear algebra and matrix operations so the general reader
will understand the code with minimum difficulties.

Matrix Algebra

CAD (computer-aided design) and CAM (computer-aided manufacturing) software have revolutionized the automotive industry, for instance. Today computer graphics forms the heart, and linear algebra the soul of modern car design. Before a new car is built, engineers design and construct a mathematical car — a wire-frame model that exists only in computer memory and on graphics display terminals. The car is also mathematically tested (to simulate impact crash-force, engine heat conduction, metal vibration-fatigue frequency, etc.) before even a prototype is built. Linear algebra is indeed the foundation of any graphics software because all the manipulations of screen images are accomplished via algebraic techniques.

If A is an m x n matrix — that is, a matrix with m rows and n columns — then the scalar entry in the ith row and the jth column of A is denoted by aij and is called the (i,j) — entry of A. The class Matrix.java has an internal array storage
as a private instance variable named A and it has an accessor method to read its value.

Jama and Jamlab

Jama is a basic linear algebra package for Java. The classes in this package enable the construction and manipulation of real, dense matrices. Jama is sufficient enough to provide functionality for routine problems and packaged in a way that is natural and understandable to non-experts. It is intended to serve as the standard matrix class for Java and will be proposed as such to the Java Grande Forum, which represents those from academia and corporations drafting proposals to Sun on Java APIs for scientific and engineering applications. Jama was developed by the National Institute of Standards and Technology (NIST) and The MathWorks Inc.. It is available for free download.

The Jama package has six classes:

  • Matrix
  • CholeskyDecomposition
  • LUDecomposition
  • QRDecomposition
  • SingularValueDecomposition
  • EigenvalueDecomposition

The Matrix class provides the fundamental operations of numerical linear algebra. Various constructors create matrices from two-dimensional arrays of double-precision floating point numbers. Various gets and sets provide access to submatrices and matrix elements. The basic arithmetic operations include matrix addition and multiplication, matrix norms and selected element-by-element array operations. In this tutorial , we discuss matrix operations using Jama.

Jamlab (Java Matrix Laboratory) is my own developed Java matrix package, which is based on the functionality of the popular scientific and engineering language called MatLab from MathWorks. Jamlab is my own attempt to write or translate functions written in MatLab to a Java version. This package contain classes that are subclassed from class Matrix of the package Jama. There are currently six classes in Jamlab:

  • Jdatafun
  • Jelfun
  • Jelmat
  • RowColumnIndex
  • Polyfit
  • Polyval

Jamlab is not yet complete — a full version will be available for free download in the future. The reader is encouraged to download Jama and Jamlab prior to continuing on to the next part of the series.

Download Jama and Jamlab and 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

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.

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Latest Posts

Related Stories