[ Index ]

PHP Cross Reference of MantisBT

title

Body

[close]

/library/ezc/Graph/src/math/ -> polynom.php (summary)

File containing the abstract ezcGraphPolynom class

Copyright: Copyright (C) 2005-2009 eZ Systems AS. All rights reserved.
License: http://ez.no/licenses/new_bsd New BSD License
Version: 1.5
File Size: 259 lines (6 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

ezcGraphPolynom:: (8 methods):
  __construct()
  init()
  get()
  set()
  getOrder()
  add()
  evaluate()
  __toString()


Class: ezcGraphPolynom  - X-Ref

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:

<code>
// Equivalent to: x^2 + .5
$polynom = new ezcGraphPolynom( array( 2 => 1, 0 => .5 ) );

// Calculate result for x = 1, echos: 1.5
echo $polynom->evaluate( 1 ), PHP_EOL;

// Build the sum with another polynom
$polynom->add( new ezcGraphPolynom( array( 1 => 1 ) ) );

// Print polynom, echos:
// x^2 + x + 5.00e-1
echo $polynom, PHP_EOL;
</code>

__construct( array $values = array()   X-Ref
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,
)

param: array $values Array with values
return: ezcGraphPolynom

init( $order )   X-Ref
Initialise a polygon

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

param: int $order Order of polygon
return: ezcGraphPolynom Created polynom

get( $exponent )   X-Ref
Return factor for one exponent

param: int $exponent Exponent
return: float Factor

set( $exponent, $factor )   X-Ref
Set the factor for one exponent

param: int $exponent Exponent
param: float $factor Factor
return: ezcGraphPolynom Modified polynom

getOrder()   X-Ref
Returns the order of the polynom

return: int Polynom order

add( ezcGraphPolynom $polynom )   X-Ref
Adds polynom to current polynom

param: ezcGraphPolynom $polynom Polynom to add
return: ezcGraphPolynom Modified polynom

evaluate( $x )   X-Ref
Evaluate Polynom with a given value

param: float $x Value
return: float Result

__toString()   X-Ref
Returns a string represenation of the polynom

return: string String representation of polynom



Generated: Thu Jul 28 15:48:31 2011 Cross-referenced by PHPXref 0.7