PHP Classes

File: examples/Equation.php

Recommend this page to a friend!
  Classes of Francisco Jose Naranjo   Equation   examples/Equation.php   Download  
File: examples/Equation.php
Role: Example script
Content type: text/plain
Description: Example of using Equation
Class: Equation
Evaluate and render polynomial equations
Author: By
Last change:
Date: 13 years ago
Size: 772 bytes
 

Contents

Class file image Download
<?php
include_once(dirname(__FILE__) . '/../classes/Equation.class.php');

/*
 * Aim
 *
 * Define an equation object and play with all the different methods that
 * has the object
 */

/*
 * Assuming equation
 *
 * y = 2x4 + 3x2 - 2x + 10
 *
 * defined coefficients will be
 */
$coeffs = array(
   
2, // 2x4
   
0, // 0x3
   
3, // 2x
   
-2, // -2x
   
10 // 10
);

/*
 * And then, equation object can be instanced
 */
$equation = new Equation($coeffs);

/*
 * Get equation degree
 */
// Prints 4
print $equation->getDegree() . "\n";

/*
 * Get some coefficients
 */
// Second order: prints 3
print $equation->coeff(2) . "\n";

// Independent: prints 10
print $equation->coeff(0) . "\n";

/*
 * Evaluate equation
 */
// If x=2 gives 50
print $equation->evaluate(2) . "\n";
?>