Microsoft Word - Matlab Resit Assignment XXXXXXXXXXdraft).docx
Department of Electrical and Electronic
Engineering
ELEC171 - ELEC172 MATLAB Resit Assignment
Deadline: Friday 10/08/2018 at 11:59 PM
-----------------------------------------------------------------------------------------------------------------------------------
INSTRUCTIONS AND GUIDANCE – READ THIS PAGE CAREFULLY
Instructions for completing and submitting this assignment
You must submit a single Word document for the entire assignment.
For each questions, you need to include several parts:
a) Your MATLAB code
The code should be cut-pasted at TEXT into the document.
Use Courier New font for the source code, with font size 11pt.
Your cut-pasted code should retain the same colour-coding that appears in MATLAB
) Output from the program (where required)
Graphs should be pasted into the document as PNG or JPG files.
Marking scheme:
The marks for each question will be based on the three criteria below
Completeness: all sections completed
Co
ectness: program code, program output, graphs, answers to questions
Coding style: appropriate names for variables, appropriate comments in the code,
appropriate line spacing for readability
ELEC171/172 MATLAB
1
Q1) Create a file called Question1.m. Your assignment document should contain the code from this file
and a screenshot of the command window after you have run the file. Your code should only
display the output from part f) in the command window.
(20 marks)
a) Create the matrix A in your file: ? =
3 0
2 2
1 8
6
1
9
0 2 6
) Using a Matlab operator, create a vector p consisting of the elements in the second
column of A.
c) Using a Matlab operator, create a vector q consisting of the elements in the third row of
A.
d) Using a Matlab operator, create variables p_len and q_len that contain the lengths of p
and q respectively.
e) Write code to create variables A_size that contain the size of A.
f) Write code that displays the variables p, A, q_len, and A_size in the command window
Q2) Create a file called “Question2.m”, and write code to ca
y out the following tasks.
(20 marks)
a) Evaluate the expression ? = ? − 6? − 3 for all values of x between 0.1 and 5.0, in steps of 0.1,
using a for loop in the program
) Plot the output from your calculations in a single figure. Your graph should be co
ectly labelled
and have a title.
Q3) Create a file called “Question3.m”, and write code to ca
y out the following tasks.
(30 marks)
?(?) =
? 0 < ? < 2
? − 2? + 4 2 < ? < 4
3? 4 < ? < 5
a) Write code for the function and save it in a file called funcxy.m.
) Write a short program that evaluates the function for 0 < x < 5
ELEC171/172 MATLAB
2
Q4) Create a file called “Question4.m”, and write code to ca
y out the following tasks.
(30 marks)
Write a program which plots the amplitude and phase of function f(t) for 0 ≤ t ≤ 10, for the complex
function
?(?) = (1 + 3?)? − 3?? + 4
Plot both the amplitude and the phase on the same figure, with the axes positioned one above the other.
Add plot titles for each plot. Add labels for the x and y axes. Include grids in your plots.
-----------------------------------------------------------------------------------------------------------------------------------
CODE EXAMPLE
The text below is an example of a program cut-pasted from MATLAB to Word, with Courier New 11 pt
font, and with the colour-coding retained from the original MATLAB file.
% Example code written to show the way programs should be included
% in the text of the MATLAB assignment.
% The program calculates cu
ent and power for a circuit containing a voltage
source and a resistor. The values of voltage and resistance are contained in
the a
ays data_voltage and data_resistance.
% data obtained from the circuit
data_voltage = [0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0];
data_resistance = [2.5, 5.5, 8.2, 11.1, 14.4, 17.9, 21.9, 25.2, 30.0, 34.7];
% calculate cu
ent based on Ohm’s Law I = V/R
cu
ent = data_voltage / data_resistance;
% calculate power based P = V^2/R
power = (data_voltage .^ 2) / data_resistance;
% END OF FILE – Question1.m