MATLAB Arithmetic Operators
➕➖✖️➗ MATLAB Arithmetic Operators
MATLAB is developed by MathWorks.
🔹 List of MATLAB Arithmetic Operators
| Operator | Name | Description |
|---|---|---|
+ |
Addition | Adds two values |
- |
Subtraction | Subtracts one value from another |
* |
Multiplication | Matrix multiplication |
/ |
Right division | Divides matrices or numbers |
\ |
Left division | Solves linear equations |
.* |
Element-wise multiplication | Multiplies element by element |
./ |
Element-wise division | Divides element by element |
.^ |
Element-wise power | Power of each element |
^ |
Power | Matrix power |
🧪 Examples with Output
1️⃣ Addition (+)
Output
2️⃣ Subtraction (-)
Output
3️⃣ Multiplication (*)
Output
📌 This is matrix multiplication.
4️⃣ Division (/)
Output
5️⃣ Left Division (\)
Output
📌 Used to solve linear equations.
6️⃣ Element-wise Multiplication (.*)
Output
7️⃣ Element-wise Division (./)
Output
8️⃣ Power Operator (^ and .^)
🔸 Scalar Power
Output
🔸 Element-wise Power
Output
⚠️ Important Notes
-
Use
*,/,^for matrix operations -
Use
.*,./,.^for element-wise operations -
Matrix dimensions must be compatible
🎯 Interview Questions: MATLAB Arithmetic Operators
🔹 Q1. What is the difference between * and .*?
Answer:* performs matrix multiplication, while .* performs element-wise multiplication.
🔹 Q2. Difference between / and ./?
Answer:/ is matrix right division, ./ is element-wise division.
🔹 Q3. What does \ operator do?
Answer:
Solves linear equations (A \ B).
🔹 Q4. Difference between ^ and .^?
Answer:^ is matrix power, .^ is element-wise power.
🔹 Q5. Can arithmetic operators be used on vectors?
Answer:
Yes, using element-wise operators.
🔹 Q6. What happens if matrix dimensions don’t match?
Answer:
MATLAB gives a dimension mismatch error.
✅ Summary Table
| Operator | Use |
|---|---|
+ - |
Addition / Subtraction |
* / \ |
Matrix operations |
.* ./ .^ |
Element-wise operations |
^ |
Matrix power |
