Skip to content

cannot multiply matrix by vector #6

Open
@sneakyimp

Description

@sneakyimp

In matlab/octave, I can define a m x n matrix (3 x 5 in this case) and multiply it by a n x 1 column vector (5 x 1 in this case). It yields a 3x1 column vector:

X = [1 1 1 1 1; 2 2 2 2 2; 3 3 3 3 3]
    X =

       1   1   1   1   1
       2   2   2   2   2
       3   3   3   3   3

octave:427> w = [1;2;3;4;5]
    w =

       1
       2
       3
       4
       5

octave:428> X * w
    ans =

       15
       30
       45

However, ghostjat cannot multiply a 3 x 5 matrix times a vector with size=5:

require __DIR__ . '/np/vendor/autoload.php';
use Np\matrix;
use Np\vector;

$x = Np\matrix::ar([
        [1,1,1,1,1],
        [2,2,2,2,2],
        [3,3,3,3,3]
]);

$w = Np\vector::ar([1, 2, 3, 4, 5]);

$p = $x->dot($w); // throws exception Mismatch Dimensions of given Objects! Obj-A col & Obj-B row amount need to be the same!
$p = $x->multiply($w); // throws exception Mismatch Dimensions of given Objects! Obj-A col & Obj-B row amount need to be the same!

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions