/** * Construct a complete Matrix with all entries set to a complex number * Takes a source matrix or array (which can be incomplete and converts each * entry to complex number type, setting a default value if entry does not exist. * * If a Matrix is supplied as $source, the data is cloned into the ComplexMatrix * converting to complex number values, with no further checks, although you * may get exceptions thrown if conversion is not possible. * * If you don't supply a default value, then 0+0i will be used * * @param Matrix|array $source Array to initialise the matrix with * @param ComplexType $normalizeDefault Value to set missing vertices * */ public function __construct($source, ComplexType $normalizeDefault = null) { if (is_null($normalizeDefault)) { $ri = RationalTypeFactory::create(0, 1); $normalizeDefault = ComplexTypeFactory::create($ri, clone $ri); } parent::__construct($source, $normalizeDefault); }
/** * ShiftMatrix constructor. * * @param IntType $size Number of required rows and columns * @param StringType $shiftType SM_TYPE_UPPER|SM_TYPE_LOWER * @param IntType|null $identityType Type of identity entries: default == IdentityType::IDM_TYPE_INT * */ public function __construct(IntType $size, StringType $shiftType, IntType $identityType = null) { $mA = (new Identity())->create([$size()]); $new = TypeFactory::createInt(0); $fS = new Shift(); if ($shiftType() == self::SM_TYPE_UPPER) { $mB = $fS($mA, [1, $new]); } if ($shiftType() == self::SM_TYPE_LOWER) { $mB = $fS($mA, [-1, $new]); } parent::__construct($mB); }
/** * Construct a complete matrix whose entries are a result of a function * * The function must accept two parameters * e.g. $function($row, $col) {return $row - $col;} * * $row and $col are 1 based * * @param callable $function * @param IntType $rows Number of required rows * @param IntType $cols Number or required columns * * @throws \InvalidArgumentException */ public function __construct(callable $function, IntType $rows, IntType $cols) { if ($rows() < 1) { throw new \InvalidArgumentException('$rows must be >= 1'); } if ($cols() < 1) { throw new \InvalidArgumentException('$cols must be >= 1'); } $source = array(); $rc = $rows(); $cc = $cols(); for ($r = 0; $r < $rc; $r++) { for ($c = 0; $c < $cc; $c++) { $source[$r][$c] = $function($r + 1, $c + 1); } } parent::__construct($source); }
/** * Construct a complete Matrix with all entries set to a rational number * Takes a source matrix or array (which can be incomplete and converts each * entry to rational number, setting a default value if entry does not exist. * * If a Matrix is supplied as $source, the data is cloned into the RationalMatrix * converting to rational number values, with no further checks, although you * may get exceptions thrown if conversion is not possible. * * @param Matrix|array $source Array to initialise the matrix with * @param mixed $normalizeDefault Value to set missing vertices * */ public function __construct($source, $normalizeDefault = 0) { $default = $this->convertNumberToRational($normalizeDefault); parent::__construct($source, $default); }