Go to CCP Homepage Go to Materials Page Go to Engineering Mathematics Materials Go to Table of Contents
Go Back One Page Go Forward One Page

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.

  1. In the MATLAB workspace, at the prompt, type

         2 + 3

    and then press RETURN or ENTER.
  2. Enter

         2 - 3
  3. Enter

         2*3
  4. Enter

         6/3
  5. 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.

  1. Enter

         ans

    Observe that your last result is still there.
  2. Enter

         2*ans

    You can compute with the result stored in ans in the same way that you can with any number.
  3. Press the up arrow once, and then press Enter.
  4. Press the up arrow several times, and note what happens. You can recover all your previous commands and re-execute them if you desire.
  5. Enter

         sqrt(5)
  6. Enter

         pi
  7. 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.

  1. Use the up arrow to recover the command sqrt(5). Edit it using the right and left arrows and compute sqrt(8+pi).
  2. Enter

         format long

    and then enter

         pi
  3. Enter

         format short

    and then enter

         pi
  4. Enter

         format short e

    and ask for the value of pi.
  5. Enter

         format rational

    and ask for the value of pi.
  6. 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

Go to CCP Homepage Go to Materials Page Go to Engineering Mathematics Materials Go to Table of Contents
Go Back One Page Go Forward One Page


| CCP Home | Materials | Engineering Mathematics | Module Contents | Back | Forward |

modules at math.duke.edu Copyright CCP and the author(s), 2000