ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
LagrangeInterpolation Class Reference

Given n points (x0,y0)...(xn-1,yn-1), the following methid computes the polynomial factors of the n-1't degree polynomial passing through the n points. More...

+ Collaboration diagram for LagrangeInterpolation:

Public Member Functions

 findPolynomialFactors ($x, $y)
 findPolynomialFactors ($x, $y)

Detailed Description

Given n points (x0,y0)...(xn-1,yn-1), the following methid computes the polynomial factors of the n-1't degree polynomial passing through the n points.

Given n points (x0,y0)...(xn-1,yn-1), the following method computes the polynomial factors of the n-1't degree polynomial passing through the n points.

Example: Passing in three points (2,3) (1,4) and (3,7) will produce the results [2.5, -8.5, 10] which means that the points are on the curve y = 2.5x² - 8.5x + 10.

See Also
http://geosoft.no/software/lagrange/LagrangeInterpolation.java.html
Author
Jacob Dreyer
Paul Meagher (port to PHP and minor changes)
Parameters
x[]float
y[]float

Example: Passing in three points (2,3) (1,4) and (3,7) will produce the results [2.5, -8.5, 10] which means that the points are on the curve y = 2.5x² - 8.5x + 10.

See Also
http://geosoft.no/software/lagrange/LagrangeInterpolation.java.html
http://source.freehep.org/jcvsweb/ilc/LCSIM/wdview/lcsim/src/org/lcsim/fit/polynomial/PolynomialFitter.java
Author
Jacob Dreyer
Paul Meagher (port to PHP and minor changes)
Parameters
x[]float
y[]float

Definition at line 21 of file LagrangeInterpolation.php.

Member Function Documentation

LagrangeInterpolation::findPolynomialFactors (   $x,
  $y 
)

Definition at line 23 of file LagrangeInterpolation.php.

References $data, $x, and $y.

{
$n = count($x);
$data = array(); // double[n][n];
$rhs = array(); // double[n];
for ($i = 0; $i < $n; ++$i) {
$v = 1;
for ($j = 0; $j < $n; ++$j) {
$data[$i][$n-$j-1] = $v;
$v *= $x[$i];
}
$rhs[$i] = $y[$i];
}
// Solve m * s = b
$m = new Matrix($data);
$b = new Matrix($rhs, $n);
$s = $m->solve($b);
return $s->getRowPackedCopy();
} // function findPolynomialFactors()
LagrangeInterpolation::findPolynomialFactors (   $x,
  $y 
)

Definition at line 24 of file LagrangeInterpolation2.php.

References $data, $x, and $y.

{
$n = count($x);
$data = array(); // double[n][n];
$rhs = array(); // double[n];
for ($i = 0; $i < $n; ++$i) {
$v = 1;
for ($j = 0; $j < $n; ++$j) {
$data[$i][$n-$j-1] = $v;
$v *= $x[$i];
}
$rhs[$i] = $y[$i];
}
// Solve m * s = b
$m = new Matrix($data);
$b = new Matrix($rhs, $n);
$s = $m->solve($b);
return $s->getRowPackedCopy();
} // function findPolynomialFactors()

The documentation for this class was generated from the following files: