University of Waterloo Faculty of Engineering Department of Electrical and Computer Engineering ECE 204A Pre-Laboratory 2 Prepared by Surname/Last Name, Legal Given/First Name(s) UW Student ID Number: 2NNNNNNN UW User ID: uwuserid @uwaterloo.ca 2A Electrical/Computer Engineering 9 February 2016 Remember to always use format long unless otherwise directed. 2.0a What are the two mechanisms for re-executing previous commands in Matlab? Your answer here. 2.1.1a Enter the Matlab commands required to construct the row vector u 4,3,7 . Copy and paste your Matlab commands with commas. Copy and paste your Matlab commands without commas. 3 2.1.2a Enter the Matlab code required to construct the column vector v 5 using both 2 the semicolon and the transpose operator. Copy and paste your Matlab commands using [ ; ; ] Copy and paste your Matlab commands using [ ]' 2.1.3.1a Using format short. Create and assign following row vectors efficiently in Matlab: i. The row vector u1 1, 2,3, 4,5 , ii. The row vector u2 1,1.5, 2, 2.5,3 , and iii. The row vector u3 5, 4,3, 2,1 . Remember to type format long after this question. Copy and paste your Matlab commands and the output here. Use u1, u2, and u3 as variable names. 2.1.3.1b Does 1:pi include ? Yes/No 2.1.3.2a Create 4-dimensional column vectors of all ones and assign it to the variable v. Copy and paste your Matlab commands and the output here. 2.1.3.3a Create a row vector containing 50 equally spaced points from 1 to 10 inclusive and ensure that the output is suppressed. Copy and paste your Matlab commands and the output here. 2.1.4a What does the following Matlab code do? >> v = rand(5,1); >> (v(1) + v(end))/2 Your description here. 2.1.5a What symbol is used to suppress the output of a Matlab command? The symbol. 2 1 4 2.1.6a Given the two vectors u 3 and v 3 , create and add the two vectors in 2 2 Matlab and assign the output to the variable w. Copy and paste your Matlab commands and the output here. 2.1.6b Subtract 1 from each entry in the vector v found in 2.1.6a. Copy and paste your Matlab commands and the output here. 2.1.7a Divide each entry in the vector v found in Question 2.1.6a by the maximum entry. The maximum entry is found by calling max(v). Copy and paste your Matlab commands and the output here. 1 6 2.1.8a Create the following two vectors u and v and calculate the inner 2 3 product. What is the angle between these two vectors in degrees? Copy and paste your Matlab commands and the output here. The angle is ??° 3 2.2.1a How many entries are there in the vector 1:pi:exp(10)? Copy and paste your Matlab commands and the output here. 2.2.2a Create a row vector of six equally spaced points from 0 to 1.5 and find the value of the tangent function at each of the six points. Copy and paste your Matlab commands and the output here. 2.2.3a Use Matlab to find the minimum value of a row vector containing 100 random entries from the open interval (0, 1). Copy and paste your Matlab commands and the output here. 2.2.3.1a Use Matlab to find the position of the minimum entry of the vector u = [3 4 -2 6 0 -4 5]; and make sure that position is assigned to the variable p. Copy and paste your Matlab commands and the output here. 3 2.2.4a What are the 1-, 2- and infinity-norms of the vector u 0 ? 4 Copy and paste your Matlab commands and the output here. 2.2.5a Given the vector v = 1:0.1:2, raise all entries in the vector to the power 3. Copy and paste your Matlab commands and the output here. 2.2.5b Explain in English what occurs here: >> linspace(0, pi, 5) .* [0 1 0 0 1] Your explanation here. 4 2.2.6a You will likely need Matlab for this question. Create a vector of 40 points going from 0 to 10. Plot the function sin(x) + 1 for these 40 points where the line is cyan and dashed (that is, use the option 'c--'). To export an image from the Matlab Figure dialog, select File→Save As... and in the Save As dialog, select the Save as type: Portable Network Graphics file (*.png) and give the file an appropriate name. You may wish to change the directory to the Desktop. Next, in Word, right click on the existing image in Figure 1 and select Change Picture... and choose the appropriate file from the Insert Picture dialog. Figure 1. The function sin(x) + 1 on [0, 10]. 2.2.6b If you plot a function with the option 'go-', what will it look like? Your answer here. 2.2.6.1a What additional commands would you use to give the plot in Figure 1 the title “The System Response”, the legend “sin(x) + 1”, to give the back ground a grid of lines, and to change the range on the y-axis to [-1, 2]? Copy and paste your Matlab commands here. 5