Skip to main content

Section 8.10 Important Functions

MATLAB includes thousands of built-in functions that can do calculations for you. That is actually one of the reasons why it is so expensive (it costs a lot of money to pay programmers to make those functions for you!). Functions in MATLAB work very similar to functions in Excel in that you give them some input (typically a number or variable that has a number stored in it) and they return a value based on some calculation. For example, if you wanted to calculate the square root of 16, you could type the following into the command window:
>> sqrt(16)
In this case, the function is sqrt() and the input is 16. When you hit enter you should see that MATLAB spits out:
ans = 4
Which is the square root of 16 (remember to leave off the semi-colon when we want to see the answer displayed in the command window). We could have also stored 16 in a variable and asked for the square root of the variable.
>> number=16
>> sqrt(number)
Will work the exact same way.
We won’t be learning about every MATLAB built-in function available, but here are a few that you may find useful right away. For your brain workout, spend a few minutes looking over table 7.3 below and practicing using those functions. I suggest trying a combination of numbers and variables as input arguments to the function.
Figure 8.10.1. Some important built-in functions that you should be able to use.

Checkpoint 8.10.2. Evaluating sin in MATLAB.

Using MATLAB, evaluate sin(360) assuming the angle is measured in radians and then assuming the angle is measured in degrees. Which result is greater?
  • Radians
  • Correct! MATLAB’s sin() function expects radians by default. sin(360) is approximately 0.959, while sind(360) is 0.
  • Degrees
  • Incorrect. sind(360) equals 0, while sin(360) (with 360 interpreted as radians) is approximately 0.959.
You have attempted of activities on this page.