BASIC INTRODUCTION TO MATLAB
 

Basic Arithmetic
Trigonometry
Logarithms and Exponentials
Variables
Retrieving Variable Values
Saving and Loading
Recording Your Steps
Helpful Links
Basic Arithmetic
How to Examples
How to:
Doing basic arithmetic in MATLAB is no more difficult than using a calculator.
We have our four most basic operations: addition, subtraction, multiplication, and division, represented by the symbols: +, -, *, and / respectively.

To work with exponents, we use the ^ symbol.

Inversely, if we want to take the square root of a number we use the sqrt( ) function. All other roots (i.e. cube root) should be performed using the ^ symbol and the inverse of our root (i.e. 1/3).

MATLAB already has the value of sqrt(-1) stored in 'i' to be used as an imaginary number. But like any
variable name, it can be changed. Just type i = sqrt(-1) to reset its value.

To find the absolute value of a number, say -3, we would type abs(-3). And, of course, order of operations does apply in MATLAB. So, don't forget to use those parentheses ( ).


Examples:
Let's say we wanted to find the value of 7, added to 3, and raised to the 3rd power, all in one MATLAB step:
     (7 + 3)^3

MATLAB would promptly return to us a value of 1000.

What if we entered (sqrt(2*32))^(1/3) into MATLAB.
First, MATLAB would compute 2*32, which is 64.
Next, MATLAB would compute sqrt(64) which we know is 8.
Next, MATLAB would compute 1/3. MATLAB uses decimal approximation, so it would temporarily store .333333... in its memory.
Finally, MATLAB would compute 8^.3333... (the cube root of 8), and return a value of 2.