<?php
 
//
 
// Edit History:
 
//
 
//  $Author: munroe $
 
//  $Date: 2006/01/22 19:41:49 $
 
//
 
//  Dick Munroe (munroe@csworks.com) 20-Jan-2006
 
//      Initial version created.
 
//
 
 
/**
 
 * @author Dick Munroe <munroe@csworks.com>
 
 * @copyright copyright @ 2006 by Dick Munroe, Cottage Software Works, Inc.
 
 * @license http://www.csworks.com/publications/ModifiedNetBSD.html
 
 * @version 1.0.0
 
 * @package Complex
 
 * @example ./example.php
 
 */
 
 
include_once 'class.Complex.php' ;
 
 
$n1 = new Complex(3, 2) ;
 
$n2 = new Complex(2, 5) ;
 
 
$theSum = new Complex($n1) ;
 
$theSum->add($n2) ;
 
 
$theSubtraction = new Complex($n1) ;
 
$theSubtraction->subtract($n2) ;
 
 
$theMultiplication = new Complex($n1) ;
 
$theMultiplication->multiply($n2) ;
 
 
$theDivision = new Complex($n1) ;
 
$theDivision->divide($n2) ;
 
 
$theSqrt = new Complex($n1) ;
 
$theSqrt->sqrt() ;
 
 
$theLog = new Complex($n1) ;
 
$theLog->log() ;
 
 
$theExp = new Complex($theLog) ;
 
$theExp->exp() ;
 
 
$theLog10 = new Complex($n1) ;
 
$theLog10->log10() ;
 
 
$theExp10 = new Complex($theLog10) ;
 
$theExp10->exp10() ;
 
 
echo "\nObject oriented operations:\n\n" ;
 
printf("number 1 =    (%f, %fi)
 
number 2 =    (%f, %fi)\n\n",
 
       $n1->real(), $n1->imaginary(),
 
       $n2->real(), $n2->imaginary()) ;
 
    
 
printf("Sum =         (%f, %fi)\n", $theSum->real(), $theSum->imaginary()) ;
 
printf("Difference =  (%f, %fi)\n", $theSubtraction->real(), $theSubtraction->imaginary()) ;
 
printf("Product =     (%f, %fi)\n", $theMultiplication->real(), $theMultiplication->imaginary()) ;
 
printf("Quotient =    (%f, %fi)\n", $theDivision->real(), $theDivision->imaginary()) ;
 
printf("Square Root = (%f, %fi)\n", $theSqrt->real(), $theSqrt->imaginary()) ;
 
printf("Log base e  = (%f, %fi)\n", $theLog->real(), $theLog->imaginary()) ;
 
printf("e**Log base e  = (%f, %fi)\n", $theExp->real(), $theExp->imaginary()) ;
 
printf("Log base 10 = (%f, %fi)\n", $theLog10->real(), $theLog10->imaginary()) ;
 
printf("10**Log base 10  = (%f, %fi)\n", $theExp10->real(), $theExp10->imaginary()) ;
 
 
$n1 = new Complex(6, 3) ;
 
$n2 = new Complex(0, 5) ;
 
 
$theSum = Complex::add($n1, $n2) ;
 
 
$theSubtraction = Complex::subtract($n1, $n2) ;
 
 
$theMultiplication = Complex::multiply($n1, $n2) ;
 
 
$theDivision = Complex::divide($n1, $n2) ;
 
 
$theSqrt = Complex::sqrt($n1) ;
 
 
$theLog = Complex::log($n1) ;
 
 
$theExp = Complex::exp($theLog) ;
 
 
$theLog10 = Complex::log10($n1) ;
 
 
$theExp10 = Complex::exp10($theLog10) ;
 
 
echo "\nProcedural operations:\n\n" ;
 
printf("number 1 =    (%f, %fi)
 
number 2 =    (%f, %fi)\n\n",
 
       $n1->real(), $n1->imaginary(),
 
       $n2->real(), $n2->imaginary()) ;
 
    
 
printf("Sum =         (%f, %fi)\n", $theSubtraction->real(), $theSubtraction->imaginary()) ;
 
printf("Product =     (%f, %fi)\n", $theMultiplication->real(), $theMultiplication->imaginary()) ;
 
printf("Quotient =    (%f, %fi)\n", $theDivision->real(), $theDivision->imaginary()) ;
 
printf("Square Root = (%f, %fi)\n", $theSqrt->real(), $theSqrt->imaginary()) ;
 
printf("Log base e  = (%f, %fi)\n", $theLog->real(), $theLog->imaginary()) ;
 
printf("e**Log base e  = (%f, %fi)\n", $theExp->real(), $theExp->imaginary()) ;
 
printf("Log base 10 = (%f, %fi)\n", $theLog10->real(), $theLog10->imaginary()) ;
 
printf("10**Log base 10  = (%f, %fi)\n", $theExp10->real(), $theExp10->imaginary()) ;
 
 
echo "\nPolar Coordinate Form:\n\n" ;
 
 
$p1 = new Polar($n1) ;
 
$p2 = new Polar($n2) ;
 
 
printf("number 1 =    (%f, %f (radians))
 
number 2 =    (%f, %f (radians))\n",
 
       $p1->radius(), $p1->theta(),
 
       $p2->radius(), $p2->theta()) ;
 
       
 
$n1 = new Complex($p1) ;
 
$n2 = new Complex($p2) ;
 
 
printf("number 1 =    (%f, %fi)
 
number 2 =    (%f, %fi)\n",
 
       $n1->real(), $n1->imaginary(),
 
       $n2->real(), $n2->imaginary()) ;       
 
       
 
$p1 = new Polar(1, -2*M_PI) ;
 
 
printf("number 3 =    (%f, %f (radians))\n",
 
       $p1->radius(), $p1->theta()) ;       
 
 
$p1 = new Polar(1, -1.5*M_PI) ;
 
 
printf("number 4 =    (%f, %f (radians))\n",
 
       $p1->radius(), $p1->theta()) ;       
 
 
echo "\n"
 
?>
 
 |