LabTest2 2023 24
LabTest2 2023 24
LAB TEST 2
AUTUMN TERM 2023
School of Computer Science and Electronic Engineering
University of Essex
Plagiarism
You are reminded that this work is for credit towards the composite mark in CE142 and that the work you
submit must therefore be your own. Any material you make use of, whether it is from textbooks, the web,
your own previous submissions or any other source, must be acknowledged in your report, and the extent
of the reference clearly indicated.
Please see your handbook for rules regarding the late submission of assignments.
Exercise 1
Q1. Write a custom MATLAB function which takes as input/argument a complex [5 pts]
number 𝑧 and returns 5 outputs (in this order): the real part 𝑅𝑒(𝑧̅), the imaginary
part 𝐼𝑚(𝑧̅), the modulus |𝑧̅| and the angle with the x-axis 𝐴𝑟𝑔(𝑧̅) of its complex
conjugate 𝑧̅, as well as the angle 𝑧,̂𝑧̅ (i.e., the angle between 𝑧 and 𝑧̅). The function
should also produce a plot graphically illustrating 𝑧 and 𝑧̅, on a complex plane.
Include in your report the Maths working/formulas that your MATLAB function
implements for the different outputs.
Hint1: Make sure your code produces correct results for input complex numbers 𝑧
of every quadrant of the complex plane.
Hint2: For angles between complex numbers, it may be easier to treat complex
numbers as 2D vectors.
Hint3: A MATLAB function is a MATLAB script embedded as standalone in a
single MATLAB *.m or *.mlx file that has a preamble (i.e., a first line of the script)
like:
where outX are the output arguments returned by the function, and inputX the input
arguments. So, your submitted MATLAB function could look like:
Note that the functionname should be the same as the filename of the M file (i.e., in
this case your M file could be named LT2_xxxxxxx_Ex1.m (replace your own
registration number) and the functionname should be LT2_xxxxxxx_Ex1. The
names of the output and input arguments are just suggestions, feel free to change
them (but, do try to give variables intuitive names taking into account what each
variable represents).
1
Q2. Find the locus of complex numbers for which it holds 𝑅𝑒 (𝑧 + 𝑧) = 5𝑅𝑒(𝑧). [10 pts]
Perform the working for finding the locus in your report. Afterwards, create and
submit a MATLAB script that plots this locus in the complex plane.
Hint1: Expressions of the form 𝑥 2 + 𝑦 2 = 𝑟 2 represent circles of radius 𝑟 whose
centre lies at the origin 𝑂(0,0) of the cartesian coordinate system.
Hint2: In order to plot the locus, one idea is to superimpose on the same figure the
plots of functions 𝑦 = 𝑓(𝑥) = +√𝑟 2 − 𝑥 2 and 𝑦 = 𝑔(𝑥) = −√𝑟 2 − 𝑥 2
Q3. Using De Moivre’s procedure, solve the complex number equation 𝑧 6 = −8. [10 pts]
Provide your analytic Maths working in your report. Subsequently, create a
MATLAB script verifying your solutions by using one of MATLAB’s equation
solvers, or by simply replacing the roots you found in the above expression.
Hint: If you choose to use a MATLAB equation solver for verification, you could
select between fsolve and sym/solve of the symbolic toolbox. Note that fsolve needs
anonymous functions/expressions as input, and will only return one root as it is a
numerical solver. In order to find all roots, you need to smartly try different starting
points (second argument of fsolve). sym/solve uses symbolic functions and will
return all roots at once. Use eval() in order to simplify the expressions of all roots
returned.
Exercise 2
Q1. Find the vector 𝑟⃗ = (𝑥, 𝑦, 𝑧) (i.e., find the unknown real numbers 𝑥, 𝑦, 𝑧) [15 pts]
which, given vectors 𝑣⃗ = (6, −3, 0) and 𝑤 ⃗⃗⃗ = (0, 0, 2), satisfies the following three
conditions:
⃗⃗
𝑣 ⃗⃗
𝑣
𝑟⃗ ⊥ 𝑤
⃗⃗⃗ × (3 − 𝑤
⃗⃗⃗), i.e., 𝑟⃗ is perpendicular to the vector 𝑤
⃗⃗⃗ × (3 − 𝑤
⃗⃗⃗)
7 7
‖𝑟⃗‖ = ‖𝑃𝑟𝑜𝑗𝑣⃗⃗+𝑤 ⃗⃗⃗ (𝑤
⃗⃗⃗)‖, i.e. the modulus of 𝑟⃗ is 4 times the absolute value
4
of the scalar projection of 𝑤 ⃗⃗⃗ on 𝑣⃗ + 𝑤
⃗⃗⃗
̂ 2 ̂ 2
𝜑̂ = 〈𝑟⃗ , 𝑤⃗⃗⃗ 〉 = 3 〈𝑣⃗ , 𝑤⃗⃗⃗ 〉 i.e., 𝑟⃗ forms an angle 𝜑̂ with vector 𝑤⃗⃗⃗ which is 3
times that of the angle formed between 𝑣⃗ and 𝑤 ⃗⃗⃗.
Include all the necessary working for finding 𝑟⃗ = (𝑥, 𝑦, 𝑧) in your report. Submit
also a MATLAB script which i) verifies your solution and ii) plots the found
vector 𝑟⃗ using MATLAB function quiver3.
Hint1: Putting together all the above information by applying the definitions you
have seen in the corresponding labs and classes will lead to a 3 × 3 system with
𝑥, 𝑦, 𝑧 as the three unknown variables, which can be then easily solved (e.g., with
replacements of one equation into the other(s)).
Hint2: Vector cross-product computation is out of the scope of the module (we
have only seen a simple formula for computing the modulus of a cross product, but
not the cross-product itself). You can use MATLAB function cross() to compute
any cross-products needed and use the result in your working for the report.
Hint3: Perform all other tedious calculations with MATLAB or a calculator.
Hint4: Consider that there may be more than one vectors 𝑟⃗ satisfying these
conditions.
Q2. Show in your report that for any vector 𝑣⃗, it holds |𝑣⃗|2 = 𝑣⃗ ∙ 𝑣⃗, i.e., that the [5 pts]
square of its modulus is equal to the dot product of the vector with itself.
Subsequently, submit a MATLAB function which verifies this property by returning
the square |𝑣⃗|2 and the dot self-product 𝑣⃗ ∙ 𝑣⃗ for any input vector 𝑣⃗ (i.e., 𝑣⃗ should
be the input argument of the function).
Hint1: Use the definitions of the modulus and the dot product for vectors.
Hint2: Consider using the MATLAB functions norm() and dot(), but, also feel free
to implement the corresponding entities yourself by definition in MATLAB.
Q3. Show in your report that for any two parallel vectors 𝑣⃗, 𝑤 ⃗⃗⃗, their cross product is [5 pts]
the zero vector 𝑣⃗ × 𝑤⃗⃗⃗ = ⃗0⃗. Subsequently, submit a MATLAB function which
receives as inputs two vectors 𝑣⃗, 𝑤
⃗⃗⃗ and returns value 1 if the two vectors are parallel,
value 2 in case they are perpendicular and 0 otherwise.
Hint1: Consider known that 𝑣⃗ × 𝑣⃗ = ⃗⃗ 0, or consider what you know about the
modulus of the cross-product |𝑣⃗ × 𝑤
⃗⃗⃗| for any two vectors 𝑣⃗, 𝑤
⃗⃗⃗.
Hint2: Consider using the MATLAB functions cross() and dot(), but, also feel free
to implement the corresponding entities yourself by definition in MATLAB.
Exercise 3
Q1. Solve the following linear system of equations exclusively by using matrix [10 pts]
algebra. Provide the working of your solution analytically in the report, showing
all the intermediate steps needed to acquire the desired solution. Subsequently,
provide a MATLAB script that computes and prints the solutions of the system.
𝑥 =𝑦+2
{
2𝑦 − 𝑥 = −1
Hint1: Solutions that do not make use of matrix algebra (specifically, determinant
and inverse matrix computation) will not be accepted and will yield 0 marks.
Hint2: Your MATLAB script may use any solution you see fit, including
“mldivide” and the “\” operator. However, it is strongly recommended that you
implement in MATLAB the same steps as in your report’s working, so as to
confirm your manual working through MATLAB scripting.
Q2. Write and submit a MATLAB script which finds and prints the matrix 𝐴 and [15 pts]
its determinant, so that the following expression is satisfied:
𝐵 𝑇 𝐴 + 𝐵 = 𝐵 −3 (|𝐵|𝑣 𝑇 𝑤 + 𝐼3 )
1 1 0
where 𝐼3 the 3 × 3 identity matrix, 𝐵 = (−2 0 −1), and where vectors
−2 −1 −1
𝑣⃗ = (2 −1 1), 𝑤 ⃗⃗⃗ = (0 1 2) are given as row vectors (i.e., 1x3 matrices).
Justify (using MATLAB comments within your MATLAB script; comments can
be included with the % operator at the beginning of the line) whether matrix 𝐴
could represent the matrix of a 3 × 3 linear equation system and, if so, solve the
system 𝐴𝑥⃗ = 𝑤 ⃗⃗⃗ and print its solution within your script.
Exercise 4
Q1. Provide in your report the Fourier Series expansion of the following periodic [12 pts]
function up to 𝑛 = 1, i.e, including the terms with coefficients: constant term
coefficient 𝑎0 , first cosine term coefficient 𝑎1 and first sine term coefficient 𝑏1 .
1 + (𝑡 − 2𝑛), 2𝑛 − 1 ≤ 𝑡 ≤ 2𝑛
𝑓(𝑡) = { 𝑛 = ⋯ , −1,0,1, ⋯
1 − (𝑡 − 2𝑛)2 , 2𝑛 ≤ 𝑡 ≤ 2𝑛 + 1
If you think that any of these coefficients should be zero, justify your assumption
in the report. All Maths working to calculate the Fourier Series coefficients and the
final form of the Fourier Series expansion up to 𝑛 = 1 should be analytically
provided in the report.
Submit also a MATLAB script that plots a figure of the first period of the periodic
function 𝑓(𝑡). The script should also compute and print the values of the
coefficients 𝑎0 , 𝑎1 , 𝑏1 using MATLAB’s symbolic toolbox sym/int to calculate the
corresponding integrals, thus verifying the solution you got with analytical
working in your report.
Q2. Write a MATLAB function that extracts the Fourier Series coefficients of any [13 pts]
periodic function up to any requested order and plots it against the estimated
function in different colors, for the first period. The function preamble should look
like this: