PHP code example of alemian95 / php-complex-numbers

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

    

alemian95 / php-complex-numbers example snippets


use Alemian95\PhpComplexNumbers\Complex;

// Create a complex number using Cartesian coordinates
$complex1 = new Complex(3.0, 4.0);

// Create a complex number using polar coordinates
$complex2 = Complex::createFromPolar(5.0, 0.92729521800161); // Equivalent to (3, 4)

// Addition
$sum = $complex1->add($complex2);

// Subtraction
$diff = $complex1->sub($complex2);

// Multiplication
$product = $complex1->mul($complex2);

// Division
$quotient = $complex1->div($complex2);

// Absolute value
$absoluteValue = $complex1->abs();

// Argument
$argument = $complex1->arg();

// Conjugate
$conjugate = $complex1->conjugate();
bash
composer