Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

CH 3

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

CHAPTER (3)

BUILT – IN
FUNCTIONS
1. Introduction

 In MATLAB, function arguments can be either scalars or matrices.

 Many of the names for MATLAB's built-in functions are the same as those defined in
the programming languages such as C, Pascal, FORTRAN and Java.

2. Some elementary functions

3. Rounding Functions

P a g e | 22
4. Factorial Function

5. Trigonometric Functions

6. Matrix size

P a g e | 23
7. Complex Numbers

P a g e | 24
8. Special values and functions

P a g e | 25
Exercise (1):
Create a vector x from -2 to +2 with an increment of 1.

a. Find the absolute value of each member of the vector.


b. Find the square root of each member of the vector.

Exercise (2):
Find the square root of both -3 and +3.

a. Use the sqrt function.


b. Use the nthroot function.

Exercise (3):
Create a vector x from -9 to +12 with an increment of 3.

a. Find the result of x divided by 2.


b. Find the remainder of x divided by 2.
c. Find ex.
d. Find ln(x) (the natural logarithm of x).
e. Find log10 (x) (the common logarithm of x).
f. Find (10!)

Exercise (4):
Calculate the following

a. sin (2θ) 𝑤ℎ𝑒𝑟𝑒 θ = 3𝜋


b. cos(θ) 𝑤ℎ𝑒𝑟𝑒 0 ≤ 0.2π ≤ 2π
c. sin−1 (1)
d. cos −1 (𝑥) where − 1 ≤ 0.2 ≤ 1
e. Cosine for (45°) :
 Convert the angle from degrees to radians, and then use the cos function.
 Use the cosd function.

f. Find the cosecant of 60. You may have to use the help function to find the appropriate
syntax.

P a g e | 26
Exercise (5):
Consider the following matrix:
4 90 85 75

2 55 65 75

3 78 82 79

[1 84 92 93]

a. Use the size function to determine the number of rows and columns in this matrix.
b. Determine the largest dimension in matrix.
c. Determine the total number of elements in matrix.

Exercise (6):
a. Create the following complex numbers:
A=1+i
B = 2 – 3i
C = 8 + 2i

b. Create a vector D of complex numbers whose real components are 2, 4, and 6 and whose
imaginary components are -3, 8, and -16

c. Find the magnitude (absolute value) of each of the vectors you created in part a and b.

d. Find the angle from the horizontal of each of the complex numbers you created in part a
and b.

e. Find the complex conjugate of vector D .

f. Use the transpose operator to fi nd the complex conjugate of vector D .

Exercise (7):
a. Use the clock function to add the time and date to your work sheet.
b. Use the date function to add the date to your work sheet.
c. Convert the following calculations to MATLAB ® code and explain
d. your results:
 322! (Remember that, to a mathematician, the symbol ! means factorial.)
 5 * 10500
 1 / 5 * 10500
 0/0

P a g e | 27

You might also like