MATLAB Tutor
Part 1: Elementary
Calculations
To send each command
entry instruction to MATLAB for processing, press the RETURN or ENTER key on
your keyboard.
- In the MATLAB workspace, at the prompt, type
2 + 3
and then press RETURN or ENTER.
- Enter
2 - 3
- Enter
2*3
- Enter
6/3
- Enter
2^3
Now you know how to add, subtract,
multiply, divide, and raise a number to a power in MATLAB – much the same way
you do with a calculator or with other software packages.
The most recent result is always
stored in a variable called ans (for ‘answer’). Only the very latest
result is stored there.
- Enter
ans
Observe that your last result is still there.
- Enter
2*ans
You can compute with the result stored in ans in the same way that
you can with any number.
- Press the up arrow once, and then press Enter.
- Press the up arrow several times, and note what happens. You can recover
all your previous commands and re-execute them if you desire.
- Enter
sqrt(5)
- Enter
pi
- Enter
i
You can use the right and left
arrows on the keyboard to move right and left to edit a command line. Thus,
you can correct mistakes by recalling a command with the up arrow and editing
to correct it. You can type over a symbol you want to change or use the backspace
key to delete it.
-
Use the up arrow to recover the command sqrt(5). Edit it using the right and left arrows and compute sqrt(8+pi).
- Enter
format long
and then enter
pi
- Enter
format short
and then enter
pi
- Enter
format short e
and ask for the value of pi.
- Enter
format rational
and ask for the value of pi.
- Finally, for real fun, enter
format hex
and ask for the value of pi.
Unless you especially want to see
the rest of your answers displayed in hexadecimal (base 16) form, change back
to
format
short
|
CCP Home |
Materials | Differential Calculus | Module Contents | Back | Forward |