$35
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.
EXAMPLE Question 1)
Given N=1, plot y=N sin(x) for 0£ £x 10. 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 𝑦 𝑥 . 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:; where q is the $9:; 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.
Q5. Given N=3, a parametric equation is given by
𝑁𝑡 𝑁𝑡H
𝑢 = 1 + 𝑡2 , 𝑣 = 1 + 𝑡2
for a range of t given as 0< <t 10. 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 𝑃 = RPSQ<)RTSQ <. Plot the power as a function of 𝑅N for 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
𝐼 =
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 . 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
𝑎𝑏 m=.=9n
𝑟 =𝑒
𝑏H cosH 𝑡 + 𝑎HsinH 𝑡
𝑎 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.