Exemplo n.º 1
0
 /**
  * Subtracts the given vector from this vector.
  *
  * @api
  * @param self $b The vector to subtract from this vector.
  * @return self The difference of the two vectors.
  * @throws Exception if the vectors are not in the same vector space.
  * @see self::_checkVectorSpace() For exception information.
  */
 public function subtract(self $b)
 {
     return $this->add($b->multiplyByScalar(-1));
 }
Exemplo n.º 2
0
<?php

require "./vendor/nubs/vectorix/src/Vector.php";
use Nubs\Vectorix\Vector;
$v = new Vector([2, 5]);
$ary = $v->components();
print $ary[0] . "  " . $ary[1] . "\n";
$w = $v->multiplyByScalar(3);
$ary = $w->components();
print $ary[0] . "  " . $ary[1] . "\n";
Exemplo n.º 3
0
 /**
  * Verify that multiplication by a scalar works.
  *
  * @test
  * @uses \Nubs\Vectorix\Vector::__construct
  * @uses \Nubs\Vectorix\Vector::components
  * @covers ::multiplyByScalar
  */
 public function multiplyByScalarWithSimpleValue()
 {
     $vector = new Vector([1, 2, 3]);
     $this->assertSame([3, 6, 9], $vector->multiplyByScalar(3)->components());
 }