PHP Classes

PHP Complex Numbers class: Perform arithmetic operations with complex numbers

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 141 All time: 9,201 This week: 45Up
Version License PHP version Categories
m2 1.0.0Custom (specified...5PHP 5, Math
Description 

Author

This package can perform arithmetic operations with complex numbers.

It can store a complex number value with real and imaginary parts.

The class can perform several types of complex number operation like:

- SQuare Root (sqrt)
- Exponentiation (pow)
- Inversion
- Absolute value (abs)
- Addition, subtraction, multiplication and division

Picture of zinsou A.A.E.Moïse
  Performance   Level  
Name: zinsou A.A.E.Moïse is available for providing paid consulting. Contact zinsou A.A.E.Moïse .
Classes: 50 packages by
Country: Benin Benin
Age: 35
All time rank: 6761 in Benin Benin
Week rank: 132 Up1 in Benin Benin Equal
Innovation award
Innovation award
Nominee: 23x

Winner: 2x

Example

<?php
require_once('ArComplex.class.php');

echo
'<pre>';
echo
'<h3>exponential form: </h3>';
var_dump($a=new Arcomplex('5.6111611111-3.59I'));
var_dump($exp=$a->Cexponentialform());
var_dump(exptocomplex($exp));
var_dump(exptocomplex("6.6613233681245*(e(-0.56916865378565*i))"));
var_dump(exptocomplex("6.6613233681245(e(-0.56916865378565i))"));
var_dump(exptocomplex("6.6613233681245.(e(-0.56916865378565.i))"));
echo
'<h3>Complex power: </h3>';
$c=new Arcomplex('0.001+0.6533I');
var_dump($c->Cpow(-2));
var_dump($c->Cpow(2));
$x=new COP(new Arcomplex($c->Cpow(-10)),new Arcomplex($c->Cpow(10)));
var_dump($x->Cmul());
$x=new COP(new Arcomplex('1+3I'),new Arcomplex('1-3I'));
echo
'<h3>Complex division and multiplication: </h3>';
var_dump($x->Cdiv());
var_dump($x->Cmul());
$x=new COP(new Arcomplex('1-1.5i'),new Arcomplex('1-i'));
var_dump($x->Cdiv());
var_dump($x->Cmul());
echo
'<h3>Complex inverse and opposite form: </h3>';
var_dump($a=new Arcomplex('-2+2I'));
var_dump($e=$a->Cinv());
var_dump($e->Cform());
var_dump($e=$a->Copp());
var_dump($e->Cform());
echo
'<h3>Complex square root: </h3>';
var_dump($a=new Arcomplex('-4'));
var_dump($e=$a->Csqrt());
var_dump($e->Cform());
$x=new COP(new Arcomplex($e->Cform()),new Arcomplex($e->Cform()));
var_dump($x->Cmul());
var_dump($a=new Arcomplex(array(-4,6)));
var_dump($e=$a->Csqrt());
var_dump($e->Cform());
$x=new COP(new Arcomplex($e->Cform()),new Arcomplex($e->Cform()));
var_dump($x->Cmul());
var_dump($a=new Arcomplex(array('Im'=>-4,'Re'=>6)));
var_dump($e=$a->Csqrt());
var_dump($e->Cform());
$x=new COP(new Arcomplex($e->Cform()),new Arcomplex($e->Cform()));
var_dump($x->Cmul());
echo
'<h3>Complex all square roots: </h3>';
var_dump($a=new Arcomplex(array(0,-0.001)));
var_dump($e=$a->AllCsqrt());
var_dump($e[0]->Cform());
var_dump($e[1]->Cform());
$x=new COP(new Arcomplex($e[0]->Cform()),new Arcomplex($e[0]->Cform()));
var_dump($x->Cmul());
$x=new COP(new Arcomplex($e[1]->Cform()),new Arcomplex($e[1]->Cform()));
var_dump($x->Cmul());
echo
'<pre>';


Details

ArComplex.class.package is a package for handling complex arithmetic on/with PHP Language. This class allows users to do all human can do on or with complex numbers. This class is very easy to use and also very easy to understand. ArComplex.class.package allows users to specify his complex number just like an array example: $a=new Arcomplex(array(-4,6)); where the first element is real and the second imaginary... or example:$a=new Arcomplex(array('Im||im||i||I||imaginary'=>-4,'Re||re||r||R||real'=>6))); here the order doesn't count or as a numeric for complex number with only real part just as example $a=new Arcomplex(-4); or even more easily as a string: example: $c=new Arcomplex('0.001+0.6533I'); or $c=new Arcomplex('0.001+0.6533i'); or $c=new Arcomplex('0.001+I'); or $c=new Arcomplex('0.001i');//the last example is a complex with just an imaginary part..... and so one.... For other examples, see the 'complextest.php' file or read the class declaration to understand... The package contains two classes: one for basics operations on one complex number and one other for operations between two complex number... For more informations or bug reporting or suggestions Please contact me at this e-mail leizmo@gmail.com

  Files folder image Files (4)  
File Role Description
Plain text file ArComplex.class.php Class ArComplex.class
Accessible without login Plain text file complextest.php Example test
Accessible without login Plain text file license Lic. license
Accessible without login Plain text file readme Doc. readme

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:141
This week:0
All time:9,201
This week:45Up