Operators allow you to perform mathematical functions on variables, evaluate conditions and decide which conditions to choose.

For all of the examples in the following tables use

A = [0 2; 2 0] and B = [0 1; 2 3]

The Matlab mathematical operators include:

**
**

Operator | Character | Example | Description |
---|---|---|---|

Addition | + | A + B [0 3;4 3] | |

Subtraction | - | A - B [0 1;0 -3] | |

Multiplication | * | A * B [4 6;0 2] | The number of columns in A must equal the number of rows in B. A*B does not equal B*A |

Right Division | / | A / B [2 0 ; -3 1] | Solves the equation Bx = A. The number of columns in A and B must be equal. |

Left Division | \ | A \ B [1 1.5; 0 0.5] | Solves the equation Ax = B. |

Element Wise | . | A .* B [0 2;4 0] | Element wise multiplication. |

The Matlab relational operators include:

**
**

Operator | Character | Example |

Less Than | < | A < B [0 0; 0 1] |

Less Than or Equal To | <= | A <= B [1 0; 1 1] |

Greater Than | > | A > B [0 1; 0 0] |

Greater Than or Equal to | >= | A >= B [1 1; 1 0] |

Equal to | == | A == B [1 0; 1 0] |

Not Equal to | ~= | A ~= B [0 1; 0 1] |

The Matlab logical operators include:

**
**

Operator | Character | Example | Description |
---|---|---|---|

And | & | A & B [0 1; 1 0] | Checks if both elements are non-zero (true). |

Or | | | A | B [0 1; 1 1] | Checks if one element is non-zero. |

Not | ~ | ~ A [1 0; 0 1] | If true returns false and vice versa. |