MATLAB Operations on MatricesObjective: To study arithmetic operation on matrices, relational operations on matrices, and logical operation on matrices. Arithmetic Operators:Operations | MATLAB Form | Comments |
---|
Array Addition | a+b | Array & matrix addition are identical | Array Subtraction | a-b | Array & matrix subtraction are identical | Array Multiplication | a.*b | Array multiplication element by element multiplication of a & b | Matrix Multiplication | a*b | For matrix multiplication no of a column in matrix a=no of a column of matrix b | Array Right Division | a./b | Element by element division of a & b | Array Left Division | a.\b | Element by element division of a & b within the Numerator. | Matrix Right Division | a/b a* | inv(b) where inv represent inverse | Matrix Left Division | a\b | inv(a)*b | Array Exponential | a.^b | Element by element exponential of a & b i.e a(i , j) ^ b( i , j) |
Examples:Relational Operators:Relational operators are used to representing conditions such as "space ? 0" and "result ? 25". They take two numerical (or string) operands. They yield a logical result (true or false). The general form is: a1 op a2 a1 and a2 are arithmetic expressions, variables, or strings. op is one of the following Operators | Operations |
---|
== | Equal to | ~= | Not equal to | > | Greater than | >= | Greater than equal to | < | Less than | <= | Less than equal to |
ExamplesLogical Operators:- &&: Logical AND with shortcut evaluation.
If the first expression is false, return false instead of calculating the second expression. It works only between scaler values. Faster because of partial evaluation. - &: Logical AND
Evaluates both expressions. It works with both scaler and array values. - ||: Logical inclusive OR with shortcut evaluation.
If the first expression is true, return true instead of calculating the second expression It works only between scaler values. Faster because of partial evaluation. - |: Logical OR
Evaluates both expressions. It works with both scaler and array values. - XOR: Logical exclusive OR
It returns true if and only if one operand is true and other is false.
Examples:Logical functions:- ischar(a): It returns true if a is character array otherwise false.
- isempty(a): It returns true if a is an empty array otherwise false.
- isinf(a): It returns true if a is infinite otherwise false.
- isnan(a): It returns true if a is not a number otherwise false.
- isnumeric(a): It returns true if a is a numerical array otherwise false.
- logical: It converts mathematical to logical.
Examples:
|