$35
Please read the file, “How to complete and upload the solution template” before you begin. Download assign3.m and fill it in and then upload the completed file on D2L drop box. Also download test_assign3.m and assign3_solutions.mat to test your answers as you go. Make sure your name and UCID are correctly filled out in the template file.
The questions are based on content from chapter 4 of the textbook “MATLAB, An introduction with applications”. Assume that all the angles are in radians except where specifically noted.
Note for this assignment in Questions 8-‐‑10 you will need to understand how to use for, and end. Use help for
to get information on how to use the for statement. You can also type
doc for
on the command line which opens the document file.
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 X2 =[ 200, 190,...,10,20]- - , calculate a vector Y2 based on the function yi = +5 100xi where xi is the ith element of X2 and yi is the ith element of Y2. Make the function return Q2 =åsin( )cosxi (yi ) .
i
3. Given vectors of samples X3=[0,1,...,100] andY3 =[10,11,...,110], calculate vector æpxi ö+2cosæçæ p ö2 ö
Z3 based on the function zi = sinèç ø÷ ççè180ø÷ x yi i ÷ø÷. xi , yi and zi are the ith
180 è
elements of X3, Y3 and Z3 respectively.
4. Solve for X4 in the matrix equation 𝐴 𝑋4 = 𝑌4 given é-4 3 1 ù é-18.2ù
A=êê 5 6 -2úú and Y4 =êê-48.8úú êë 2 -5 4.5úû êë 92.5 úû
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
𝑅, = 1ℎ−, coscos𝜃𝜃,,
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
𝑠𝑡𝑑 =
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
P 9 𝑄 =
9;Q8;NO
9. Given M=11, determine the value of
: <Q =U
𝑄 = (𝑚 + 𝑛 + 𝑘)
8;U9;QV;9
10. Given K=12, determine the value of
W V 8
𝑄 =
V;Q 8;Q 9;NO