CLASS FuncGenerator
(Defined in: jpgraph.php : 676)
 FuncGenerator 
 E() 
 FuncGenerator() 
 

Class usage and Overview
A utility class to help with function plots. This class supprots both ordinary one-variable plots with one dependent variable as well as polar plots. Basically you create an instance of this class with the function you want to plot as a string argument. The function should be created using 'x' as the independent variable. You then invoke its evaluation method 'E()' with the range for the independent variable and possibly a step size. The method then returns an array of X, and Y values that represents the plot. Please remember that the string should be specified with single quotes since otherwise PHP will try to interpret the variable in the string. For example, to specify a simple cos() plot you specify: $f = new FuncGenerator('cos($x)';

 


Class Methods

 

 

function E($aXMin,$aXMax,$aSteps)
Evaluate a X-Y function

ArgumentDefaultDescription
$aXMin  Min x-value
$aXMax  Max x-value
$aSteps 50 Number of steps

Description
Evaluate the previous specified function between the specified values. The return two arrays representing the X and Y coordinates for the function. 

Example

// Create a simple linear plot
$f = new FuncGenerator('cos($x) * sin($x)');
list($xdata,$ydata) = $f->E(-2*M_PI, 2*M_PI);

$lp1 = new LinePlot($ydata,$xdata);

// Create a simple polar plot (a circle)
$p = new FuncGenerator('cos($i)', 'sin($i)');
list($x2data,$y2data) = $f->E(-2*M_PI, 2*M_PI);

$lp2 = new LinePlot($y2data,$x2data);

//...

 

 

function FuncGenerator($aFunc,$aXFunc)
Create a new function generator.

ArgumentDefaultDescription
$aFunc  Function
$aXFunc '' X-Function

Description
Creates a new funciton generator. You can create both a linear plot as well as polar plot. For linear, one-variable plots, you must use '$x' as the independent variable. For polar plots you should use the index '$i' for the generating functions.  

Example

// Create a simple linear plot
$f = new FuncGenerator('cos($x) * sin($x)');
list($xdata,$ydata) = $f->E(-2*M_PI, 2*M_PI);

$lp1 = new LinePlot($ydata,$xdata);

// Create a simple polar plot (a circle)
$p = new FuncGenerator('cos($i)', 'sin($i)');
list($x2data,$y2data) = $f->E(-2*M_PI, 2*M_PI);

$lp2 = new LinePlot($y2data,$x2data);

//...