MECH 2220 Lecture HW 1
NAME:_____type your name here_______
Page 1 of 2
Chapra, Third Edition, Chapter 2
Complete the following problems. Modify this document to include your solution. Use
the highlighter to highlight your text answers in yellow. Include figures as needed. Note
that Matlab will allow you to save the figure as a jpeg or png file.
1. Give the Matlab command to create the following matrix as M in the workspace:
1 2 3
4 5 6
7 8 9
a. Use the sum command to sum the third column of the matix. Use the :
operator to indicate all rows.
b. Give the command that will find the product of M22 and M31
c. Give the result for >>a=M(2:3,[1,3])
2. Give the commands that will create a smooth plot of sin(x) from x=0 to x=2*pi
3. What is the difference between the size function and the length function?
4. What is the difference between clc and clear?
5.
Explore the linspace function. In your own words, describe the input and output
of linspace. Give example of when the function might be useful. Give the matlab
code for that example.
6. Use colon notation to generate vectors equivalent to:
a. [10,8,6,4,2,0,-2]
b. linspace(10,100,5)
7. A ball is traveling upward with an initial velocity of 100 m/s. The velocity is
reducing at a rate of 9.8 m/s/s. So the velocity is given by v=–g*t+v_0 and the
position is given by y= -0.5*g*t^2 +v_0*t+y_0. The initial altitude of the ball is
10 meters.
a. Create a velocity vector, v_v, that contains the velocity of the ball at times
[0 2 4 6 8 10] seconds
b. Create a position vector, p_v, that contains the velocity of the ball at times
[0 2 4 6 8 10] seconds
c. Plot velocity and position as functions of time on the same plot. Include a
legend, plot title, and axis labels (with units).
MECH 2220 Lecture HW 1
NAME:_____type your name here_______
Page 2 of 2
8. The follow command is entered in MATLAB:
>>r3=[0,1,0,1,0];
>>c6=[1,1,1]’;
>>M=[4:-2:-4;1,2,3,4,5;r3];
>>M=[M,c6]
a. Determine the resulting matrix M
b. Give the matlab command to store the second row of M in the r2
c. Give the command that will compute the number of rows and columns in
M. Store the results as nr and nc.
d. Give the command that will compute the dot product of the first and third
row of M
9. The motion of a projectile fired from a cannon at an angle 𝜃 with initial velocity
𝑣0 is given by
𝑔
𝑦 = 𝑦0 + 𝑣0 ⋅ sin(𝜃) ⋅ 𝑡 − 𝑡 2
2
𝑥 = 𝑥0 + 𝑣0 ⋅ cos(𝜃) ⋅ 𝑡
Given g=9.8 m/s/s, 𝑦0 = 1 m, 𝑣0 = 100 m/s, produce 5 plots for angles
[15:15:85] degrees. The vertical axis should indicate the y value, and the
horizontal axis should indicate the x value for each point. Each plot should stop
once the y value is less than zero. Use different symbols for each plot. Include a
legend and axis labels