Zeta Components - high quality PHP components

Zeta Components Manual :: Docs For Class ezcGraphPolynom

Graph::ezcGraphPolynom

Class ezcGraphPolynom

Provides a class for generic operations on polynoms

This class is mainly used for internal representation of polynoms in the average dataset ezcGraphDataSetAveragePolynom.

It provides only very basic mechanisms to work with polynoms, like adding of polynomes and evaluating the polynom with a given number, to calculate a point in the chart for a given value on the x axis.

Beside this the __toString implementation may be used to echo the polynoms calculated by the least squares mechanism in the above mentioned average datasets. The class does not provide any options to customize the output.

The class can be used like:

  1.   // Equivalent to: x^2 + .5
  2.   $polynom = new ezcGraphPolynom( array( 2 => 1, 0 => .5 ) );
  3.  
  4.   // Calculate result for x = 1, echos: 1.5
  5.   echo $polynom->evaluate( 1 ), PHP_EOL;
  6.  
  7.   // Build the sum with another polynom
  8.   $polynom->add( new ezcGraphPolynom( array( 1 => 1 ) ) );
  9.  
  10.   // Print polynom, echos:
  11.   // x^2 + x + 5.00e-1
  12.   echo $polynom, PHP_EOL;

Source for this file: /Graph/src/math/polynom.php

Version:   //autogentag//

Member Variables

protected array $values
Factors of the polynom

An example: Polynom: 2 * x^3 + .5 * x - 3 Array: array ( (int) 3 => (float) 2, (int) 1 => (float) .5, (int) 0 => (float) -3, )

Method Summary

public ezcGraphPolynom __construct( [ $values = array()] )
Constructor
public ezcGraphPolynom add( $polynom )
Adds polynom to current polynom
public float evaluate( $x )
Evaluate Polynom with a given value
public float get( $exponent )
Return factor for one exponent
public int getOrder( )
Returns the order of the polynom
public ezcGraphPolynom init( $order )
Initialise a polygon
public ezcGraphPolynom set( $exponent , $factor )
Set the factor for one exponent
public string __toString( )
Returns a string represenation of the polynom

Methods

__construct

ezcGraphPolynom __construct( [ $values = array()] )

Constructor

Constructs a polynom object from given array, where the key is the exponent and the value the factor. An example: Polynom: 2 * x^3 + .5 * x - 3 Array: array ( (int) 3 => (float) 2, (int) 1 => (float) .5, (int) 0 => (float) -3, )

Parameters:
Name Type Description
$values array Array with values

add

Adds polynom to current polynom

Parameters:
Name Type Description
$polynom ezcGraphPolynom Polynom to add

evaluate

float evaluate( float $x )

Evaluate Polynom with a given value

Parameters:
Name Type Description
$x float Value

get

float get( int $exponent )

Return factor for one exponent

Parameters:
Name Type Description
$exponent int Exponent

getOrder

int getOrder( )

Returns the order of the polynom

init

ezcGraphPolynom init( int $order )

Initialise a polygon

Initialise a polygon of the given order. Sets all factors to 0.

Parameters:
Name Type Description
$order int Order of polygon

set

ezcGraphPolynom set( int $exponent , float $factor )

Set the factor for one exponent

Parameters:
Name Type Description
$exponent int Exponent
$factor float Factor

__toString

string __toString( )

Returns a string represenation of the polynom

Documentation generated by phpDocumentor 1.4.3