You are on page 1of 7

# ENG EK 127

Worksheet 1
Name: Vladislav Navolochnyy

## Lab Section: _____C3______

Instructions: The solutions to these problems must be completed by the time you arrive
for the next class (Note: for Problems 1 and 2, just follow the instructions. You do not
need to have any solution for these problems.). The minimum set for this worksheet is
all problems. You must test all solutions in MATLAB. Problems 8 and 9 are also to be
submitted through the edge course site.
1. Get into MATLAB. In the Command Window, experiment with variables by doing
the following tasks in sequence:
At the prompt, type the following:
>> 4^2
Type who to see your variables at this point.
EDU>> 4^2
ans =
16
EDU>> who
Your variables are:
ans

localeStruct

Hit the up arrow. Notice that goes back to the previous command. Hit the up
arrow again to go back to the expression 4^2. Modify this (by using the left
arrow) to assign the expression to a variable called myvar.
Type who to see your variables at this point.
EDU>> myvar = 4^2
myvar =
16
EDU>> who
Your variables are:
ans

localeStruct myvar

The default variable ans can be used just like any other variable. Write an
assignment statement that will add 2 to the current value of ans.

EDU>> ans + 2
ans =
18

EDU>> clear
EDU>> who
EDU>>

EDU>> pi
ans =
3.1416

## Enter the assignment statement pi = 2\15

EDU>> pi = 2\15
pi =
7.5000

Now type pi again. Oops; you just wiped out the value of the built-in pi! Restore
it by typing clear pi. Now type pi again.
EDU>> pi
pi =
7.5000
EDU>> clear pi
EDU>>

2. More on helpType help by itself at the prompt to see a list of all of the help topics.
Notice that one of them is
matlab\elfun
- Elementary math
functions.
Type help elfun at the prompt to see a list of the elementary math functions.
Notice the functions under the category Rounding and remainder; youll be using some of
these for some of these problems. To find out about any of these functions, type help and
then the function name, e.g. help fix will give a description of the fix function.

## EDU>> 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.
cos
- Cosine.
cosd
- Cosine of argument in degrees.
cosh
- Hyperbolic cosine.
acos
- Inverse cosine.
acosd
- Inverse cosine, result in degrees.
acosh
- Inverse hyperbolic cosine.
tan
- Tangent.
tand
- Tangent of argument in degrees.
tanh
- Hyperbolic tangent.
atan
- Inverse tangent.
atand
- Inverse tangent, result in degrees.
atan2
- Four quadrant inverse tangent.
atan2d
- Four quadrant inverse tangent, result in degrees.
atanh
- Inverse hyperbolic tangent.
sec
- Secant.
secd
- Secant of argument in degrees.
sech
- Hyperbolic secant.
asec
- Inverse secant.
asecd
- Inverse secant, result in degrees.
asech
- Inverse hyperbolic secant.
csc
- Cosecant.
cscd
- Cosecant of argument in degrees.
csch
- Hyperbolic cosecant.
acsc
- Inverse cosecant.
acscd
- Inverse cosecant, result in degrees.
acsch
- Inverse hyperbolic cosecant.
cot
- Cotangent.
cotd
- Cotangent of argument in degrees.
coth
- Hyperbolic cotangent.
acot
- Inverse cotangent.
acotd
- Inverse cotangent, result in degrees.
acoth
- Inverse hyperbolic cotangent.
hypot
- Square root of sum of squares.
Exponential.
exp
- Exponential.
expm1
- Compute exp(x)-1 accurately.
log
- Natural logarithm.
log1p
- Compute log(1+x) accurately.
log10
- Common (base 10) logarithm.
log2
- Base 2 logarithm and dissect floating point number.
pow2
- Base 2 power and scale floating point number.

## realpow - Power that will error out on complex result.

reallog - Natural logarithm of real number.
realsqrt - Square root of number greater than or equal to zero.
sqrt
- Square root.
nthroot - Real n-th root of real numbers.
nextpow2 - Next higher power of 2.
Complex.
abs
- Absolute value.
angle
- Phase angle.
complex - Construct complex data from real and imaginary parts.
conj
- Complex conjugate.
imag
- Complex imaginary part.
real
- Complex real part.
unwrap
- Unwrap phase angle.
isreal
- True for real array.
cplxpair - Sort numbers into complex conjugate pairs.
Rounding and remainder.
fix
- Round towards zero.
floor
- Round towards minus infinity.
ceil
- Round towards plus infinity.
round
- Round towards nearest integer.
mod
- Modulus (signed remainder after division).
rem
- Remainder after division.
sign
- Signum.
EDU>> help fix
fix - Round toward zero
This MATLAB function rounds the elements of A toward zero, resulting in an array
of integers.
B = fix(A)
Reference page for fix
See also ceil, floor, round
3. Use the built-in function namelengthmax to find out the maximum number of
characters that you can have in an identifier name under your version of MATLAB.
EDU>> namelengthmax
ans =
63
4. Explore the format command in more detail. Use help format to find options.
Experiment with format bank to display dollar values.
5. Find a format option that would result in the following output format:

## >> 5/16 + 2/7

ans =
67/112
6. Use help elfun or experiment to answer the following questions:
Is fix(3.5) the same as floor(3.5)?
yes
EDU>> fix(3.5)
ans =
3.00
EDU>> floor(3.5)
ans =
3.00
They are the same

yes
EDU>> fix(3.4)
ans =
3.00
EDU>> fix(-3.4)
ans =
-3.00

EDU>> fix(3.2)
ans =
3.00
EDU>> floor(3.2)
ans =

3.00

## Is fix(-3.2) the same as floor(-3.2)?

No
EDU>> fix(-3.2)
ans =
-3.00
EDU>> floor(-3.2)
ans =

-4.00
Is fix(-3.2) the same as ceil(-3.2)?

7.
The function sin calculates and returns the sine of an angle in radians. Use help
elfun to find the name of the function that returns the sine of an angle in degrees. Verify
that calling this function and passing 90 degrees to it results in 1.
sind

## - Sine of argument in degrees.

EDU>> Y = sind(90)
Y=
1.00
8. (edge Submit Problem) A vector can be represented by its rectangular coordinates x
and y or by its polar coordinates r and . The relationship between them is given by
the equations:
x = r * cos()
y = r * sin()
Assign values for the polar coordinates to variables r and theta. Then, using these
values, assign the corresponding rectangular coordinates to variables x and y.
9. (edge Submit Problem) Find MATLAB expressions for the following
19

31.2

tan()

10. Look at the Class 1 Commands and Functions, and make sure that you understand
everything and play around with all of the functions listed! You are responsible for
understanding all of these functions.