PHP code example of scorpiot1000 / complex-base

1. Go to this page and download the library: Download scorpiot1000/complex-base library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

scorpiot1000 / complex-base example snippets


    use ScorpioT1000\ComplexBase\Complex\Form\Complex;
    use ScorpioT1000\ComplexBase\Complex\Form\ComplexTrigonometric;
    
    ...

    $a = new Complex(4, 4);
    $b = new Complex(2, 2);
    
    echo 'a = '. $a . PHP_EOL;
    echo 'b = '. $b . PHP_EOL;
    
    echo '-a = '.$a->negative() . PHP_EOL;
    echo 'a + b = '.$a->add($b) . PHP_EOL;
    echo 'a - b = '.$a->sub($b) . PHP_EOL;
    echo 'a * b = '.$a->mul($b) . PHP_EOL;
    echo 'a / b = '.$a->div($b) . PHP_EOL;

    $aTrig = $a->toTrigonometric();

    echo $aTrig;
    echo $aTrig->add(new ComplexTrigonometric(0, M_PI)); // rotate 180deg