learningMatlab

First steps

Useful operators and commands for this unit…

+, -, .^, ( ), :, whos, openvar

The following are really the most basic “exercises” to get everyone started on doing simple maths on the command line. Nothing particularly exciting here, apart from the last couple of exercises that are a bit more maths-y (but not particularly Matlab-heavy).

In the command prompt, try to work out the following:

  1. 3/2
  2. value of π (as in 3.1415.. the ratio of circumference to diameter of a circle; what do you think this could be called in Matlab?)
  3. two times π
  4. 2 to the power of 8
  5. 4 to the power of 3
  6. 64 to the power of one third
  7. (bonus) the square root of 81 (not using the sqrt() function?!)

And look at the following exercises briefly to make some vectors / list of numbers.

  1. Make a variable a containing the number 10
  2. Find out more about a with whos and openvar
  3. Make a column vector b containing 1 2 3
  4. Now redefine b to be a row vector containing 1 2 3
  5. Look at how the colon (:) can be used to fill in numbers. Look at help colon
  6. Compare the results of 1:10 and 1:2:10 and 10:-1:1
  7. Add the number 15 to the vector b
  8. Create c=2:2:12 and try to add the wrongly shaped [1 2] to c. Note down the error message!
  9. Try joining the vectors a and b. Now the vectors b and c. Should this work?

Next

Simple commands for getting the mean, std, etc.