$29.99
MATLAB Assignment 4
, Section A
This problem set has become a bit of a staple of the MATLAB seminar- I hope you enjoy it! Note
that at a minimum, all plots should have a title, x-axis and y-axis labels, and if there are more than
one function in the same figure, a legend as well. Additionally, make sure your plot’s axis bounds
are adequate.
Please submit this homework as .m files with suppressed output (obviously, the plots should still be
displayed). Remember that all lectures and homeworks may be found at github.com/guybaryosef/ECE210-
materials. This homework is due by 4:00 PM on February 26th to guybymatlab@gmail.com. Remember to also bring a hardcopy in to class!
1. Who Gives a Schmidt!? Professor Mintchev has just assigned you 20 tedious Gram Schmidt
orthonormalization problems! Luckily, you are a master of MATLAB so you decide to build a
function which can handle them all for you.
a. Create a function called gramSchmidt. The input to the function should be a 2-D array, where
each column is a vector. The set of input vectors can be assumed to be linearly independent.
Implement GS to create an orthonormal set of vectors from these input vectors. Store them as
columns in an output matrix in the same format as the input 2-D array. Feel free to use the
norm function as needed.
b. After you’ve created this function, you’d like a way to test if it works. Create another function
called isOrthonormal which takes in a 2-D array as input. This function should return a logical
1 if all the columns are orthonormal and logical 0 otherwise. Be careful with this - direct floating
point equality comparison is a bad idea. Instead apply a threshold to the difference of the two
numbers like so: if |x − xˆ| > then... The eps function might be useful here. You can add a
nice big fudge factor to make the tolerance big enough that it works, just don’t make it huge
(Note that there is also the matter of spanning the same space as the original matrix, don’t
worry about this condition).
c. Finally, we would like to estimate another vector as a linear combination of these orthonormal
vectors (i.e. to project a vector onto the space of the orthonormal vectors). Implement a
function called orthoProj which takes as input a vector to be estimated as well as a 2-D array
of orthonormal vectors (similar format as previously) and returns as its output the estimated
projected vector.
d. Test all of the above functions on some random complex vectors (use rand to make a random
vector). First test the case where there are more elements in each vector than the number of
vectors. Then test the case where the number of vectors is equal to the number of elements in
each vector. Compare the errors.
1
e. Uniformly sample sin(x) over [0, 2π]. Generate 5 Gaussian graphs using the pdf:
1
√
2πσ2
exp
−(x − µ)
2
σ
2
Give each Gaussian a standard deviation of 1 (σ = 1) and pick the mean from a linearly spaced
vector ranging from 0 to 2π (µ ∈ {0, π/2, π, 3π/2, 2π}). Consider using ndgrid for compact
code.
(a) Plot the Sinusoid and Gaussians on the same plot.
(b) Use gramSchmidt to create an orthonormal set of vectors from the generated Gaussians.
Use orthoProj to estimate the sinusoid from that set of vectors.
(c) Create a 2x1 subplot. Plot the sinusoid and the estimated sinusoid together on the upper
plot. Plot the orthonormal basis functions on the lower plot. Remember to properly format
all your plots!
2