PHP code example of webit / complex-number

1. Go to this page and download the library: Download webit/complex-number 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/ */

    

webit / complex-number example snippets


$num1 = new Complex(1, 3); // (real, imaginary)
// or
$num2 = Complex::create(5, 5);

$sum = $num1->add($num2);
$diff = $num1->sub($num2);
$prod = $num1->mul($num2);
$quot = $num1->div($num2);
$sqrt = $num1->sqrt();
$abs = $num1->abs(); // scalar
$conjugated = $num1->getConjugated();

$complexArray1 = new ComplexArray(array(23.4, 23.55)); // accepts array of floats or array of Complex
// or
$complexArray2 = ComplexArray::create(array(23.4, 23.55));

foreach ($complexArray1 as $complex) {
    echo $complex ."\n";
}