Description
Do NOT use loops (e.g. for) for questions 1-7
1. Given a vector of samples X1 [ 200, 190,…,10, 20] = - - , determine the sum of all of the
elements of the vector X1.
2. Given a vector of samples X 2 [ 200, 190,…,10, 20] = - - , calculate a vector Y2 based on
the function 5 100 i i y x = + where i x is the ith element of X 2 and i y is the ith element of
Y 2. Make the function return 2 sin( )cos i i ( )
i
Q xy =å .
3. Given vectors of samples X3 [0,1,…,100] = andY3 [10,11,…,110] = , calculate vector
Z3 based on the function
2
sin 2cos
180 180
i
i ii
x
z xy
æ ö p æ ö æ ö p
= + ç ÷ ç ÷ ç ÷ è ø è ø è ø
. i x , i y and i z are the ith
elements of X3, Y3 and Z3 respectively.
4. Solve for X4 in the matrix equation 𝐴 𝑋4 = 𝑌4 given
43 1
56 2
2 5 4.5
A
é ù -
ê ú = - ê ú
ê ú ë û -
and
18.2
4 48.8
92.5
Y
é ù -
ê ú = -
ê ú
ê ú ë û
5. A rocket flying straight up measures the angle 𝜃 with the horizon at different heights, ℎ.
The measured values of 𝜃 and ℎ are stored in two binary data files named Q5h.mat
(contains a row vector of measured values of ℎ) and Q5theta.mat (contains a row
vector of measured values of 𝜃). All angles are in degrees and height is given in 𝑘𝑚.
Write a Matlab function that does the following:
a. Reads the two binary data files and generates a row vector 𝑅 whose
elements are the estimates the radius of the earth at each data point using
𝑅, = ℎ, cos 𝜃,
1 − cos 𝜃,
b. Outputs the average of all of the values of 𝑅.
6. The Matlab function rand() generates a random number between 0 and 1. Write a
Matlab function that does the following:
a. Given 𝑀 = 10,000 generate M random numbers using rand(), and store
them in a column vector of X.
b. Computes the standard deviation (std) of the elements of X using
𝑠𝑡𝑑 = 1
𝑀
𝑋8 − 1
𝑀
𝑋9
:
9;<
: =
8;<
and outputs the result. Do NOT use Matlab’s built-‐‑in functions std() or var() for this
question.
7. A digital magnetometer is a small low-‐‑power integrated circuit (IC) that measures the
intensity of the earth’s magnetic field and produces digital outputs that correspond to
the magnetic field intensity along two or three axes of a local coordinate system. This
electronic component is ubiquitously used in smartphones, GPS devices, vehicles, airplanes,
etc. to produce accurate compass heading information.
The measured values of the earth’s magnetic field (in nT) along the x and y axes of a
magnetometer are provided in a binary data file named Q7xy.mat. The data file contains a
5 by 2 matrix named Mdata. Write a Matlab function that does the following:
a. Reads the binary data file.
b. Assigns the values of the 1st column of Mdata to row vector 𝑋7.
c. Assigns the values of the 2nd column of Mdata to row vector 𝑌7.
d. Outputs a row vector 𝑍7 whose elements are the estimates of the relative
compass heading from
𝑧, = 𝑎𝑐𝑟𝑡𝑎𝑛 𝑦,
𝑥,
×
180
𝜋
Use for loops to answer questions 8-10.
8. Given N=10, determine the value of
𝑄 = sin
𝑛𝑚
10
9
8;NO
P
9;Q
9. Given M=11, determine the value of
𝑄 = (𝑚 + 𝑛 + 𝑘)
=U
V;9
<Q
9;Q
:
8;U
10. Given K=12, determine the value of
𝑄 = 𝑘 𝑚 cos 𝑛 + 𝑚
8
9;NO
V
8;Q
W
V;Q

