Table Of Contents

Elementary built-in functions

MATLAB has a very large library of built-in functions. We can try a set of elementary functions by typing:

      >> help elfun

Elementary math functions.

Trigonometric.
  sin         - Sine.
  sind        - Sine of argument in degrees.
  sinh        - Hyperbolic sine.
  asin        - Inverse sine.
  asind       - Inverse sine, result in degrees.
  asinh       - Inverse hyperbolic sine.
                      :
                      :

The help command is used to acquire some information about commands or toolboxes. Here elfun is the set of all elementary built-in functions. A function has a name and an argument in parentheses. For example, the sin function calculates the sine of a number:

>> x=pi/6, sin(x)
        x =
    0.5236

        ans =
    0.5000

We assigned a value of pi/6 to x and then calculate the value of sin(pi/3) which is 1/2. If we are still not sure how to use it, just type:

 >> help sin
 SIN    Sine of argument in radians.
  SIN(X) is the sine of the elements of X.

  See also ASIN, SIND.

     Overloaded methods:
codistributed/sin

The information from help gives us an instruction on how to use the sin command. Here the argument of sin is radians.

There are other categories of elementary functions such as Exponential, Complex and Rounding and remainder. Let’s see an example with complex values. MATLAB recognizes either i or j as the square root of -1:

>> i
ans =
0 + 1.0000i
>> j
ans =
0 + 1.0000i

However, both i and j can be variables too. Therefore when we assign a value to each of them, they store the new values:

>> i=5, j=8
i =
    5
j =
    8

For this reason, we prefer not use i and j as variables since they will return a complex value if you forget to assign values to them. Now let’s use abs and angle commands to calculate the magnitude and the phase of a complex number:

>> clear i
>> x=1+3*i, abs(x), angle(x)

x =
1.0000 + 3.0000i
ans =
 3.1623
ans =
    1.2490

Since we have just assigned 5 to i, we have to clear the variable i first by using the clear command. Now i will be interpreted as the square root of -1. We assign 1+3i to x so its magnitude is \sqrt{1^2+3^2} and the phase is \arctan(3). Of course, we can check if the commands abs and ``angle` did the right thing by typing:

>> sqrt(1+9), atan(3)

ans =
    3.1623
ans =
    1.2490

Exercise

  1. A trigonometric identity is given by

\cos^2(x/2)=\frac{\tan x+ \sin x }{2\tan x}

Verify that the identity is correct by calculating each side of the equation, substuting x = \pi/5

  1. Verify that 2^x 2^y = 2^{x+y} and \log(x)+\log(y) = \log(xy) for some values of x and y. Consult the log command.
  2. Calculate

\frac{(3-4 \mathrm{j})^2}{2+ \mathrm{j}} \cdot e^{\mathrm{j} \pi/4}

and compute its magnitude and phase.

  1. The roots of the equation ax^2+bx+c = 0 is given by x = \frac{-b \pm \sqrt{b^2-4ac}}{2a}. Use this to solve x^2+3x+2=0 and verify the solution.
  2. Verify the Euler’s formula

e^{\mathrm{j} x } = \cos x  + \mathrm{j} \sin x

for x = 0, \pi/4, respectively.

  1. What is an analytical form of \mathrm{j}^\mathrm{j} ? Is it real or complex ? Verify the Euler’s equation

e^{\mathrm{j} \pi} + 1 = 0

and use it to compute \mathrm{j}^\mathrm{j}.