/** * @param string $name * @param string $type */ public function __construct($name, $type) { $this->type = $type; $default = new \morph\property\StatefulCollection($this); $default->setPermissableType($type); parent::__construct($name, $default); }
public function store($value, array $attribute) { $value = parent::store($value, $attribute); if ($this->isNull($value)) { return; } return \Owl\safe_json_encode($value, JSON_UNESCAPED_UNICODE); }
/** * Returns an array of complex numbers representing the frequency spectrum * of real valued time domain sequence array. (count($array) must be integer power of 2) * Inspired by http://rosettacode.org/wiki/Fast_Fourier_transform#Python * * @param array $array Real-valued series input, eg. time-series. * @return array Array of complex numbers representing input signal in Fourier domain. * @throws \Exception */ public static function fft($array) { $arrayLength = count($array); if ($arrayLength <= 1) { return array(new Complex($array[0], 0)); } if (log($arrayLength) / M_LN2 % 1 !== 0) { throw new \Exception('Array length must be integer power of 2'); } $even = self::fft(self::segment($array, 0, 2)); $odd = self::fft(self::segment($array, 1, 2)); $result = array(); $halfLength = $arrayLength / 2; for ($k = 0; $k < $arrayLength; ++$k) { $phase = -2 * M_PI * $k / $arrayLength; $phasor = new Complex(cos($phase), sin($phase)); if ($k < $halfLength) { $result[$k] = $even[$k]->add($phasor->multiply($odd[$k])); } else { $result[$k] = $even[$k - $halfLength]->subtract($phasor->multiply($odd[$k - $halfLength])); } } return $result; }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return Complex the loaded model * @throws CHttpException */ public function loadModel($id) { $model = Complex::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
/** * Returns the quotient of this complex number * and the given complex number. * * @param object Complex $c The given complex number. * @return object Complex The quotient. */ public function div(Complex $c) { $denom = $c->getReal() * $c->getReal() - $c->getImag() * $c->getImag(); return new Complex(($this->getReal() * $c->getReal() - $this->getImag() * $c->getImag()) / $denom, ($this->getImag() * $c->getReal() - $this->getReal() * $c->getImag()) / $denom); }
/** * Returns the cosine of this complex number. * * @return Complex the cosine of this complex number. */ public function cos() { $e = new Complex(M_E, 0); $i = new Complex(0, 1); $negativeI = new Complex(0, -1); $numerator = $e->complexPow($i->multiply($this))->add($e->complexPow($negativeI->multiply($this))); return $numerator->divide(new Complex(2, 0)); }
public function assertComplexEquals($expected, $actual, $delta = 0) { if ($expected[0] === '#') { // Expecting an error, so we do a straight string comparison if ($expected === $actual) { return true; } $this->_errorMessage = 'Expected Error: ' . $actual . ' !== ' . $expected; return false; } $expectedComplex = new Complex($expected); $actualComplex = new Complex($actual); if (!is_numeric($actualComplex->getReal()) || !is_numeric($expectedComplex->getReal())) { if ($actualComplex->getReal() !== $expectedComplex->getReal()) { $this->_errorMessage = 'Mismatched String: ' . $actualComplex->getReal() . ' !== ' . $expectedComplex->getReal(); return false; } return true; } if ($actualComplex->getReal() < $expectedComplex->getReal() - $delta || $actualComplex->getReal() > $expectedComplex->getReal() + $delta) { $this->_errorMessage = 'Mismatched Real part: ' . $actualComplex->getReal() . ' != ' . $expectedComplex->getReal(); return false; } if ($actualComplex->getImaginary() < $expectedComplex->getImaginary() - $delta || $actualComplex->getImaginary() > $expectedComplex->getImaginary() + $delta) { $this->_errorMessage = 'Mismatched Imaginary part: ' . $actualComplex->getImaginary() . ' != ' . $expectedComplex->getImaginary(); return false; } if ($actualComplex->getSuffix() !== $actualComplex->getSuffix()) { $this->_errorMessage = 'Mismatched Suffix: ' . $actualComplex->getSuffix() . ' != ' . $expectedComplex->getSuffix(); return false; } return true; }
} else { print "Please input right num"; exit; } } } else { if (strpos($complex, "+")) { $real = $num[0][0]; $imaginary = 1; } else { if (strpos($complex, "-")) { $real = $num[0][0]; $imaginary = -1; } else { $real = 0; $imaginary = $num[0][0] + "0"; } } } } } else { $real = $complex + "0"; $imaginary = 0; } $return = ['real' => $real, 'imaginary' => $imaginary]; return $return; } } $complex = Complex::getInstance(); $complex->operation("input", "2+i"); $complex->operation("plus", "-3-5i");
$this->real = $this->real - $b->real; $this->imaginary = $this->imaginary - $b->imaginary; } function mult(Complex $b) { $this->real = $this->real * $b->real; $this->imaginary = $this->imaginary * $b->imaginary; } public function __toString() { if ($this->imaginary > 0) { return sprintf("(%g, +%g)", $this->real, $this->imaginary); } return sprintf("(%g, %g)", $this->real, $this->imaginary); } } function compare($x, $y) { if ($x == $y) { echo $x . " is equal to " . $y . PHP_EOL; } else { echo $x . " is not equal to " . $y . PHP_EOL; } } $Complex = new Complex(5, 6); $Complex1 = new Complex(1, -4); echo $Complex . PHP_EOL; echo $Complex1 . PHP_EOL; echo $Complex->diff($Complex1); echo compare($Complex, $Complex1); echo $Complex . PHP_EOL;
public function store($value, array $attribute) { $value = parent::store($value, $attribute); return $value ? json_encode($value, JSON_UNESCAPED_UNICODE) : null; }
<head> <meta charset="utf-8"> </head> <?php class Complex { public $a; public $b; public $c; public $d; public function myFunction($c, $d) { $a = "1"; $b = "i"; $c = $c; $d = $d; $e = $c * $a + $d * $b; echo "计算的复数值为:" . $e; } } $cal = new Complex(); echo $cal->myFunction("3", "3");
break; } $array[$j['id']] = $court . "-" . $j['judge_name'] . "-" . $j['desg_code'] . "-" . $j['judge_code']; } ?> <?php echo $form->dropDownListControlGroup($model, 'judge_id', $array, array()); ?> <?php echo $form->dropDownListControlGroup($model, 'est_id', CHtml::listData(Establishments::model()->findAll(array('order' => 'est_name ASC')), 'id', 'est_name'), array('span' => 5)); ?> <?php $complex = Complex::model()->findAllByAttributes(array('district' => $model->dist), array('order' => 'name ASC')); //print_r($model->distcode);exit; $array = array(); foreach ($complex as $j) { $array[$j['type'] . "-" . $j['name']] = $j['type'] . "-" . $j['name']; } ?> <?php echo $form->dropDownListControlGroup($model, 'complex', $array, array()); ?> <?php } ?>