Using the C++ Math Library    

Operators

MATLAB supports relational and arithmetic operators. Relational operators typically perform some type of comparison between their two operands, both of which must be the same size, and return an array of ones and zeros the same size as the input arrays. A one in the result array indicates the relationship between the corresponding elements of the input arrays is true, while a zero indicates that relationship is false. The result of a relational operation is always a logical array, an array consisting entirely of ones and zeros.

Arithmetic statements in MATLAB look much like arithmetic expressions in mathematics textbooks or programming languages like C or Fortran. For example, to multiply two arrays, X and Z, and store the result in a third array Y, write Y = X * Z. Note that Y does not necessarily have to exist (but that X and Z must) before this expression is executed.

MATLAB supports the familiar arithmetic operators, +, *, -, / as well as several others, including ^ (exponentiation) and ' (transpose). There are two broad types of arithmetic operators in MATLAB, array operators and matrix operators.

The array operators are two character operators (except for + and -); the first character is always a . (period). Array operators treat the elements of their array operands individually. For example, C = A .* B represents elementwise, rather than matrix, multiplication of A and B. Each element of the result, C, is the product of the corresponding elements of A and B, that is,
C[i] = A[i] * B[i].

Matrix operators are less uniform. There is no single simple formula that describes the behavior of all the matrix operators in MATLAB.

Three of the most useful MATLAB operators are :, (), and []. The first special operator, :, has two different meanings. : permits the generation of sequences of numbers and acts as a wildcard in array subscripts. For example, the expression 1:10 expands into the sequence 1 2 3 4 5 6 7 8 9 10.

The second special operator, (), for array indexing, works closely with :. A simple array subscript, for example, A(3,9), returns the element at the intersection of row three and column nine in the array A. If you want more than a single element, use the : wildcard operator. For example, the expression
A(3, :) returns a vector (1-by-N) of all the elements in the third row of the array A.

The third of the three special operators, [], concatenates arrays, either vertically or horizontally. For example, [1 2 ; 3 4 ] horizontally concatenates 1 and 2 into a vector, 3 and 4 into another vector, and then vertically concatenates the two vectors into a square array.

Within the [] operator, spaces or commas indicate horizontal concatenation, and the semicolon, vertical concatenation.


 Data Types Functions