CE142 MATHEMATICS FOR ENGINEERS
LAB TEST 2
AUTUMN TERM 2023
School of Computer Science and Electronic Engineering
University of Essex
Submission due on Friday 15th December 2023 (week 11) at 13:59:59
Submit electronically via FASER
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.
Submission instructions and assessment:
This lab test counts for 15% of the overall mark for the module.
The lab test consists of four (4) exercises that must be solved through mathematical working on
paper and suitable MATLAB code.
The MATLAB code for all exercises (answering all questions therein) should be written and saved
in a MATLAB M-file (*.m) or Live Code File Format (*.mlx) created with MATLAB’s editor.
Clearly indicate (using comments) which exercise and question each piece of code corresponds to.
Use the following convention to name your MATLAB scripts:
LT2_RegistrationNumber_Ex1.m ( or .mlx)
Your MATLAB scripts should run without producing any errors when called from the MATLAB
command prompt and should produce the required output (figures, printouts, etc.)
Where required, mathematical workings and justifications should be included in a single Word or
PDF report. Make sure you state clearly in your report document which exercise and question each
piece of mathematical working corresponds to. State your registration number on the first page of
your report. Do not include MATLAB code or MATLAB figures in the report. Use the
following convention to name your Word or PDF file: LT2_RegistrationNumber.docx (.pdf)
Use Word Equation Editor, Latex or any other editor of your choice that can export a PDF to write
mathematical equations. Handwritten scanned solutions will also be accepted. However, make sure
that the handwriting is legible and the scans are of good quality. Points will be deducted if your
answers are illegible.
Provide adequate mathematical justification for all your answers. Points will be deducted for
failing to provide adequate mathematical reasoning even for answers that are otherwise
correct.
Please do not zip the MATLAB script and the report when uploading to FASER.
This lab test is to be done individually. Every student should submit their own report and MATLAB
code. Automatic and manual plagiarism checks will be applied.
Your mark (with written feedback) will be returned to you within four weeks in the term time.
Lab Test 2
Exercise 1
Q1. Write a custom MATLAB function which takes as input/argument a complex
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:
[out1, out2, out3, out4, out5] = functionname(input1, input2, input3)
where outX are the output arguments returned by the function, and inputX the input
arguments. So, your submitted MATLAB function could look like:
[Rezconj, Imzconj, Modzconj, Argzconj, Anglezzconj] = LT2_xxxxxxx_Ex1(z)
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).
[5 pts]
Q2. Find the locus of complex numbers for which it holds ( +
1
) = 5().
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
[10 pts]
Q3. Using De Moivre’s procedure, solve the complex number equation 6 = −8.
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.
[10 pts]
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 , , )
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
4
‖⃗⃗+⃗⃗⃗(⃗⃗⃗)‖, i.e. the modulus of is
7
4
times the absolute value
of the scalar projection of ⃗⃗⃗ on ⃗ + ⃗⃗⃗
̂ = 〈 , ̂⃗⃗⃗〉 =
2
3
〈⃗ , ̂⃗⃗⃗〉 i.e., forms an angle ̂ with vector ⃗⃗⃗ which is
2
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.
[15 pts]
Q2. Show in your report that for any vector ⃗, it holds |⃗|2 = ⃗ ∙ ⃗, i.e., that the
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.
[5 pts]
Q3. Show in your report that for any two parallel vectors ⃗, ⃗⃗⃗, their cross product is
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.
[5 pts]
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
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.
[10 pts]
Q2. Write and submit a MATLAB script which finds and prints the matrix and
its determinant, so that the following expression is satisfied:
+ = −3(|| + 3)
where 3 the 3 × 3 identity matrix, = (
1 1 0
−2 0 −1
−2 −1 −1
), and where vectors
⃗ = (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.
[15 pts]
Exercise 4
Q1. Provide in your report the Fourier Series expansion of the following periodic
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 − ( − 2)2, 2 ≤ ≤ 2 + 1
= ⋯ , −1,0,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.
[12 pts]
Q2. Write a MATLAB function that extracts the Fourier Series coefficients of any
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:
[a0, an, bn, fs] = LT2_xxxxxxx_Ex4_2_myfourier(f, flim, N)
The inputs should be:
i) f: 1xK MATLAB array of K symbolic variables, each specifying the
function rule of one of the K segments within a single period of the
function that must be approximated. Example: f = [t+pi, pi-t] specifies
the two segments of a single period of a triangular wave. The symbolic
independent variable is assumed to be t (use syms t)
ii) flim: 1x(K+1) MATLAB array of K real numbers defining the limits of
the K segments in a single period of the periodic function to be
approximated. The first and last number of the array define the limits of
the overall period, so that the period T can be extracted as T=flim(end)-
flim(1). All segments K of the single period of the function are
assumed to be continuous, so that flim(1) and flim(2) specify the limits
of the first segment, flim(2) and flim(3) the limits of the second
segment, and flim(K) and flim(K+1) define the limits of the last
segment. In the above example, flim should be flim=[-pi, 0, +pi].
iii) N: Integer scalar number with N>1 specifying the maximum order of
Fourier coefficients to be computed.
The outputs of the function should be:
i) a0: Constant term Fourier Series coefficient (scalar number)
ii) an: MATLAB array of size N with the cosine term Fourier Series
coefficients up to order N
iii) bn: MATLAB array of size N with the sine term Fourier Series
coefficients up to order N
fs: symbolic MATLAB variable specifying the Fourier Series representation of
function f up to order N
[13 pts]