com.hedgehog.math.functions
Class LagrangianPolynomialFunction

java.lang.Object
  extended by com.hedgehog.HObject
      extended by com.hedgehog.math.functions.Function
          extended by com.hedgehog.math.functions.XYVectorPolynomialFunction
              extended by com.hedgehog.math.functions.LagrangianPolynomialFunction
All Implemented Interfaces:
java.lang.Comparable, java.util.Comparator

public class LagrangianPolynomialFunction
extends XYVectorPolynomialFunction

Title: LagrangianPolynomialFunction - represents the Lagrangian polynomial function.

Description: Lagrangian polynomial function.

Copyright: Copyright (c) Hedgehog Software 2007-2009.

Company: Hedgehog Software

Since:
1.0
Version:
1.1

Field Summary
 
Fields inherited from class com.hedgehog.math.functions.XYVectorPolynomialFunction
mxi, myi
 
Fields inherited from class com.hedgehog.math.functions.Function
method
 
Fields inherited from class com.hedgehog.HObject
mID, mName
 
Constructor Summary
LagrangianPolynomialFunction(FloatingPointVector xi, FloatingPointVector yi)
          Constructor.
LagrangianPolynomialFunction(LagrangianPolynomialFunction object)
          Copy constructor.
 
Method Summary
 double firstDerivative(double x)
          Evaluates the first derivative.
 double getValue(double x)
          Evaluates L(x).
 OneVariablePolynomial lagrangianPolynomial()
          Returns the interpolating Lagrangian polynomial L(x).
 OneVariablePolynomial lagrangianPolynomial(int i)
          Returns the Lagrangian polynomial for Li(x).
 double Lix(double x, int i)
          Evaluates Li(x).
 double Lixd(double x, int i)
          Evaluates Li'(x).
 
Methods inherited from class com.hedgehog.math.functions.XYVectorPolynomialFunction
findXInterval, getXI, getYI, interpolateY, isValid, setXI, setYI, taylorsSeriesFirstDerivative, taylorsSeriesSecondDerivative, toString
 
Methods inherited from class com.hedgehog.math.functions.Function
getMethod, setMethod
 
Methods inherited from class com.hedgehog.HObject
clone, compare, compareTo, copy, equals, getID, getName, hashCode, hasID, hasName, setID, setName
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LagrangianPolynomialFunction

public LagrangianPolynomialFunction(FloatingPointVector xi,
                                    FloatingPointVector yi)
                             throws java.lang.IllegalArgumentException
Constructor. For example, the following approximates sin(x) in the interval [0:pi]:
  hedgehog.math.vectors.FloatingPointVector xi = new hedgehog.math.vectors.FloatingPointVector(5);
        hedgehog.math.vectors.FloatingPointVector yi = new hedgehog.math.vectors.FloatingPointVector(5);
        xi.setValueOpt(0.0,0); xi.setValueOpt(Math.PI/4.0,1); xi.setValueOpt(Math.PI/2.0,2); xi.setValueOpt(3.0*Math.PI/4.0,3); xi.setValueOpt(Math.PI,4);
        yi.setValueOpt(0.0,0); yi.setValueOpt(0.707,1);       yi.setValueOpt(1.0,2);         yi.setValueOpt(0.707,3);           yi.setValueOpt(0.0,4);
        LagrangianPolynomialFunction lpf = new LagrangianPolynomialFunction(xi,yi);
        System.out.println("lpf: " + lpf);
        System.out.println("lpf.getValue(0.2pi): " + lpf.getValue(0.2*Math.PI));
        System.out.println("lpf.getValue(0.6pi): " + lpf.getValue(0.6*Math.PI));
 
with output:
 lpf.getValue(0.2pi): 0.5871616  // exact: 0.587785
 lpf.getValue(0.6pi): 0.9511936  // exact: 0.951057
 

Parameters:
xi - x values.
yi - y values.
Throws:
java.lang.IllegalArgumentException - Thrown if xi and yi are not of the size.

LagrangianPolynomialFunction

public LagrangianPolynomialFunction(LagrangianPolynomialFunction object)
Copy constructor.

Parameters:
object - Object to copy.
Method Detail

Lix

public double Lix(double x,
                  int i)
           throws java.lang.IllegalArgumentException
Evaluates Li(x).

Parameters:
x - Value of x.
i - Index of x values.
Returns:
Value of Li(x).
Throws:
java.lang.IllegalArgumentException - Thrown if i<0 or i>=mxi.size().

Lixd

public double Lixd(double x,
                   int i)
            throws java.lang.IllegalArgumentException
Evaluates Li'(x).

Parameters:
x - Value of x.
i - Index of x values.
Returns:
Value of Li'(x).
Throws:
java.lang.IllegalArgumentException - Thrown if i<0 or i>=mxi.size().

firstDerivative

public double firstDerivative(double x)
Evaluates the first derivative.

Parameters:
x - Value at which derivative is required.
Returns:
First derivative at x.

lagrangianPolynomial

public OneVariablePolynomial lagrangianPolynomial(int i)
                                           throws java.lang.IllegalArgumentException
Returns the Lagrangian polynomial for Li(x).

Parameters:
i - Index of x values.
Returns:
Lagrangian polynomial for Li(x).
Throws:
java.lang.IllegalArgumentException - Thrown if i is out of range.

lagrangianPolynomial

public OneVariablePolynomial lagrangianPolynomial()
Returns the interpolating Lagrangian polynomial L(x).

Returns:
The interpolating Lagrangian polynomial L(x).

getValue

public double getValue(double x)
Evaluates L(x).

Parameters:
x - x value at which to find y.
Returns:
Interpolated value at the specified x.