O'Reilly logo

GNU Octave by Jesper Schmidt Hansen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – doing multiplication operations

Let us try to perform some of the same operations for multiplication as we did for addition:

octave:75> a*a

ans = 4

octave:76> a*b

ans =
    2    4    6

octave:77> b*b

error:  operator *:  nonconformant arguments (op1 is 1x3, op2 is 1x3)

octave:78> b*c

ans = 14

What just happened?

From Command 75, we see that * multiplies two scalar variables just like standard multiplication. In agreement with linear algebra, we can also multiply a scalar by each element in a vector as shown by the output from Command 76. Command 77 produces an error—recall that b is a row vector which Octave also interprets as a 1 x 3 matrix, so we try to perform the matrix multiplication (1 x 3)(1 x 3), which is not valid. In Command ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required