예제 #1
0
<?php

if (isset($_POST)) {
    $complexNumber = new ComplexNumber((int) $_POST['real'], (int) $_POST['imaginary']);
    $complexNumber->square();
    $addcomplexNumber = new ComplexNumber((int) $_POST['add_real'], (int) $_POST['add_imaginary']);
    $complexNumber->add($addcomplexNumber);
    $results = unserialize($_POST['results']);
    $results[] = array($complexNumber->real, $complexNumber->imaginary);
} else {
    $results = array();
}
?>
<form action="#" method="POST">
<fieldset>
	Square: <input type="text" name="real" value="<?php 
if (isset($complexNumber)) {
    echo $complexNumber->real;
}
?>
" /> +
	<input type="text" name="imaginary" value="<?php 
if (isset($complexNumber)) {
    echo $complexNumber->imaginary;
}
?>
" /> i<br/>
	Add: <input type="text" name="add_real" value="<?php 
if (isset($_POST['add_real'])) {
    echo $_POST['add_real'];
}
예제 #2
0
<?php

error_reporting(E_ALL);
require_once 'complex_number.php';
$lf = "\n";
// $lf = '<br />';
$numbers = array(new ComplexNumber(1, 5), new ComplexNumber('-2-4i'), new ComplexNumber(), new ComplexNumber('4+5i'), new ComplexNumber(array(5, 1)), new ComplexNumber('-5-1i'), new ComplexNumber('7+0i'), new ComplexNumber('18'), new ComplexNumber(''), new ComplexNumber('5.5+1.5i'), new ComplexNumber(-5.5, -1.5));
foreach ($numbers as $key => $number) {
    echo $key + 1 . ' number: ' . $number . $lf;
}
echo $lf . 'Operations: ' . $lf;
echo '1 number + 2 number: ' . ComplexNumber::add($numbers[0], $numbers[1]) . $lf;
echo '2 number + 5 number: ' . $numbers[1]->add($numbers[4]) . $lf;
echo '4 number - 2 number: ' . ComplexNumber::subtract($numbers[3], $numbers[1]) . $lf;
echo '7 number - 6 number: ' . $numbers[6]->subtract($numbers[5]) . $lf;
echo '5 number inversion: ' . ComplexNumber::invert($numbers[4]) . $lf;
echo '2 number inversion: ' . $numbers[1]->invert() . $lf;
echo '4 number + (6-8i): ' . ComplexNumber::add($numbers[3], '6-8i') . $lf;
echo '4 number + (13+2i): ' . $numbers[3]->add('13+2i') . $lf;
echo 'is 5 number real: ' . ComplexNumber::isReal($numbers[4]) . $lf;
echo 'is (3+7i) real: ' . ComplexNumber::isReal('3+7i') . $lf;
echo 'is (3) real: ' . ComplexNumber::isReal('3') . $lf;
echo 'is 3 number imaginary(not real): ' . ComplexNumber::isImaginary($numbers[2]) . $lf;
echo 'is 7 number real: ' . $numbers[6]->isReal() . $lf;
echo '10 number + 11 number: ' . ComplexNumber::add($numbers[9], $numbers[10]) . $lf;
foreach ($numbers as $number) {
    $number = null;
}
예제 #3
0
<?php

$maxIterations = 50;
$step = 1 / 20;
$topLeft = array(-1.5, 1);
$bottomRight = array(0.5, -1);
if ('cli' != php_sapi_name()) {
    echo "<pre><center>";
}
$c = new ComplexNumber(-0.8, 0.156);
for ($imaginary = $topLeft[1]; $imaginary > $bottomRight[1]; $imaginary = $imaginary - $step) {
    for ($real = $topLeft[0]; $real < $bottomRight[0]; $real = $real + $step) {
        $z = new ComplexNumber($real, $imaginary);
        $iterationCount = 0;
        while ($z->lessThanTwo() && $iterationCount < $maxIterations) {
            $z->square();
            $z->add($c);
            ++$iterationCount;
        }
        if ($iterationCount >= $maxIterations) {
            echo '*';
        } else {
            echo ' ';
        }
    }
    echo PHP_EOL;
}
if ('cli' != php_sapi_name()) {
    echo "</centre></pre>";
}