PHP code example of filmtools / polynomial

1. Go to this page and download the library: Download filmtools/polynomial library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

filmtools / polynomial example snippets


$ composer 
+HTML
public function findX( float $y ) : float;


use FilmTools\PolynomialModel\FromCoefficientsInterpolator;

// Use these X values every time:
$x_iterable = array(1,2,3);
$fci = new FromCoefficientsInterpolator( $x_iterable );

// Now find Y for each X
$coefficients_iterable = [
  0 => 2, 
  1 => 3
];

$interpolated = $fci( $coefficients_iterable ); 
// SplFixedArray [ 5, 8, 11 ]


$fci = new FromCoefficientsInterpolator;

$coefficients = array(2,3);
$x_values = array(1,2,3);

// Now find Y for each X
$interpolated = $fci( $coefficients, $x_values); 
// SplFixedArray [ 5, 8, 11 ]


use FilmTools\PolynomialModel\CoefficientsProviderInterface;
use FilmTools\PolynomialModel\FromCoefficientsInterpolator;

class MyModel implements CoefficientsProviderInterface
{
  public function getCoefficients(): \SplFixedArray
  {
    return \SplFixedArray::fromArray(array(2,3));
  }
}

$x_values = array(1,2,3);
$fci = new FromCoefficientsInterpolator( $x_values );
$interpolated = $fci( new MyModel ); 
// SplFixedArray [ 5, 8, 11 ]


use FilmTools\PolynomialModel\MultipleInterpolator;

$coefficients = array(2,3);
$mi = new MultipleInterpolator( $coefficients );

$x_iterable = array(1,2,3);
$interpolated = $mi->interpolate( $x_iterable );
$interpolated = $mi( $x_values );
// SplFixedArray [ 5, 8, 11 ]


use FilmTools\PolynomialModel\DerivativeCoefficientsProvider;
use FilmTools\PolynomialModel\CoefficientsProviderInterface;

class MyModel implements CoefficientsProviderInterface
{
  public function getCoefficients(): \SplFixedArray
  {
    // Keys are exponents, values are factors!
    return \SplFixedArray::fromArray( [0=>16, 1=>30, 2=>5, 3=> 18 ]);
  }
}
$my_provider = new MyModel;

$derivation_provider = new DerivativeCoefficientsProvider( $my_provider );
$coefficients = $derivation_provider->getCoefficients();
// SplFixedArray( 0 => 30, 1 => 10, 2 => 54)

use FilmTools\PolynomialModel\DerivativeCoefficientsProvider;
use FilmTools\PolynomialModel\MultipleInterpolator;

$derivated_coefficients = new DerivativeCoefficientsProvider( new MyModel );
$interpolator = new MultipleInterpolator( $derivated_coefficients );

$x_values = array(1,2,3);
$slopes = $interpolator->interpolate( $x_values );
// SplFixedArray 94, 266, 546