Description
Important Notes and Instructions:
• This assignment is about plotting 2D and 3D graphs in Matlab. Complete this
assignment by filling in the template file, assign4.m. As usual, all you need to do is to
submit the completed template file.
• As usual assume that all the angles are in radians. The questions are based on content
from chapters 5 and 10 of the textbook “Matlab, An introduction with applications”.
• When you open the assign4.m template you will see a form created for each question.
This assignment will be semi-auto-marked and the provided template is the form that the
instructor has to review to mark your assignment. Please don’t modify it.
• The template is designed such that all of the graphing commands, e.g. plot(x,y),
xlabel(‘x’), etc. must be written as a string array like graph=’plot(x,y)’.
Within this string all single quotes must become double quotes like
graph=’plot(x,y);xlabel=(‘’x’’)’.This however does not apply to
variables and functions which will be created in the workspace as soon as you run the
code.
• To create and see the graph you can use the command eval(graph) (you don’t
actually have to do this as it is done for you when you run test_assign4.m).
• Do not use the figure() command within your Matlab script as this will interfere with
the overall plotting program.
• Do not use the axis() command, since the auto-checker will uses random number inputs
and the size of the graph will change
• It is essential that you do not deviate from the template as it will make the job of the
instructor extremely difficult – and then you will be asked to come and demo your file in
person.
• Before you submit your script file, make sure there are no syntax errors.
• Note that instead of a single solution file on D2L there is a list of the solution figures.
An example is provided in the next page.
ENEL101 Assignment 4 Page 2
EXAMPLE Question 1)
Given N=1, plot y=N sin(x) for 0 10 £ £x . Use 100 points for your graph. Apply a grid and
labels on the abscissa and ordinate of the graph.
In the regular MATLAB command window you would type:
x=linspace(0,10,100);
y=N*sin(x);
plot(x,y);
grid on;
xlabel(‘x’);
ylabel(‘y’);
However, for the purposes of this assignment you have to create a string that contains all the
plotting commands. Within this string all single quotes must become double quotes for it to
work:
graph=’plot(x,y);grid on;xlabel(”x”);ylabel(”y”)’;
See assign4.m to see how to do Question 1. Run test_assign4.m to see the plot.
Q2. Given N=5, plot the function � � = $ %&’ (
()*+,../0 − 2(
3
for −5 ≤ � ≤ 10. Use 1000 points for
your graph. Apply a grid and labels on the abscissa and ordinate of the graph.
Q3. Given N=1, an antenna has a radiation pattern given as � � = %&’ $9:;
$9:; where q is the
azimuth angle. Assume that the formula is valid over the range of -£ £ pqp . Generate a polar
plot of the radiation pattern. Use 400 points for your graph.
Q4. Given N=3, the function � � = (<)$()2
=.> ()? is given.
Plot the function for −4 ≤ � ≤ 3. Label the axis, use a grid and place a title over your plot. Use
50 points for your graph. Limit the y axis of the graph from -12 to +10. Use red dots for the 50
data points and a black * on the last data point. Enlarge the marker size to ‘20’ pts.
ENEL101 Assignment 4 Page 3
Q5. Given N=3, a parametric equation is given by
� = ��
1 + �2 , � = ��H
1 + �2
for a range of t given as 0 10 < <t . Use subplot() to produce the following two plots. Use
100 points for each graph.
A) In the first subplot �(�) and �(�) are superimposed.
B) In the second subplot assume � along the abscissa and � along the ordinate. Apply a grid
and labels on the abscissa and ordinate of the graphs.
Q6. An electric circuit that includes a voltage source �K with an internal resistance �K and a load
resistance �N is assumed. The power � dissipated in the load is given by � = PQ
<RS
RS)TQ <. Plot the
power as a function of �N for 1 ≤ �N ≤ 10 Ω given that �K = 12 V and �K = 2.5 Ω. Use 100
points for your graph. Apply a grid and labels on the abscissa and ordinate of the graphs.
Q7. An RLC circuit with an alternating voltage source is assumed. The source voltage �K is
given by �K = �Ysin (�^�), where �^ = 2��^ in which �^ is the driving frequency. The
normalized amplitude of the current, �, in this circuit is given by
� = 1
�H + �^� − 1
�^�
H
where � (Ω), � (H), and � (F) are the resistance of the resistor, the capacitance of the capacitor,
and the inductance of the inductor, respectively. Write a function named that accepts � (H) and �
(F) as input arguments and uses the mesh command to make a 3-D plot of � (z-axis) for 0.5/
�� ≤ �^ ≤ 1.5/ �� and for 10 ≤ � ≤ 40 Ω. Label all the axes.
Q8. An elliptical staircase that decreases in size with height can be modeled by the parametric
equations
� = �cos � , � = �sin � , � = ℎ�
2��
where
� = ��
�H cosH � + �HsinH �
�m=.=9n
� and � are the semi-major and semi-minor axes of the ellipse, ℎ is the staircase height, and � is
the number of evolutions that the staircase makes. Write a function that accepts �, �, ℎ, � as input
arguments and generates a 3-D plot of the staircase. Create a vector � for the domain 0 to 2��
and use the plot3 command.