Vectors and Scalar
A scalar is just a fancy word for a number; it is used to distinguish numbers from vectors or matrices.
Arithmetic with matrices and scalars
You can use the arithmetic operators +, -, *
and / on a matrix and a scalar. The operation is applied to each
element of the matrix.
>>> r=[4, 5, 6] r = 4.00 5.00 6.00 >>> r1=r*6 r1 = 24.00 30.00 36.00 >>> r2=(r1-20)/2 r2 = 2.00 5.00 8.00 >>> c=[0.5; 3.5] c = 0.50 3.50 >>> c1=c+0.5 c1 = 1.00 4.00
Functions of matrices
You can apply functions on matrices, the function is then applied to each element of the matrix.
>>> c=[4;16] c = 4.00 16.00 >>> sqrt(c) ans = 2.00 4.00
by Malin Christersson under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 Sweden License