Spring 2016 - Wright State University

Wright State University
Department of Mechanical and Materials Engineering
Spring 2016
ME 1020: ENGINEERING PROGRAMMING WITH MATLAB
MID-TERM EXAM 2
Open Book, Closed Notes, Do Not Write on this Sheet
Create a Separate MATLAB Script File for Each Problem
Submit all MATLAB files (.m) to Dropbox on Pilot
Each MATLAB File Must Have the Following Header:
PRINT YOUR NAME:
CIRCLE ONE:
GRADE MY EXAM
DO NOT GRADE MY EXAM
Problem 1 (6 Point): Create a MATLAB Script File using a FOR loop to calculate the following function over
the range 0 ≀ 𝑑 ≀ 4πœ‹:
0 for 𝑦 β‰₯ 0.5 or 𝑦 ≀ βˆ’0.5
𝑧={
𝑦 for
βˆ’0.5 < 𝑦 < 0.5
where 𝑦 = sin(𝑑). Plot 𝑧 versus 𝑑. Make sure to use enough points to create a smooth curve. Provide a plot title
and labels for the axes.
Problem 2 (7 Points): The (π‘₯, 𝑦) coordinates of an object (in meters) as a function of time 𝑑 are given by
π‘₯(𝑑) = 5𝑑 βˆ’ 10,
𝑦(𝑑) = 25𝑑 2 βˆ’ 120𝑑 + 144
The distance of the object from the origin (0,0) is given by 𝑑 = √π‘₯ 2 + 𝑦 2 . Create a MATLAB script file that
uses a WHILE loop that increments time from 𝑑 = 0 by steps of 0.01 seconds to determine the first time 𝑑
when the distance from the origin is less than 𝑑 = 15 meters. Plot 𝑑 versus 𝑑. Provide a plot title and labels for
the axes.
Problems 3 and 4 are on the back of this page.
Problem 3 (3 Points): Create a MATLAB Script File to generate a three-dimensional line plot of the following
system of equations over the parametric range 0 ≀ 𝑑 ≀ 6πœ‹:
π‘₯(𝑑) = [1 + 0.25 cos(75𝑑)] cos(𝑑) ,
𝑦(𝑑) = [1 + 0.25 cos(75𝑑)] sin(𝑑),
𝑧(𝑑) = 𝑑 + 2 sin(75𝑑)
Make sure to use enough points to create a smooth curve. Provide a plot title and labels for the axes.
Problem 4 (4 Points): Create a MATLAB Script File to generate a surface mesh plot of the following function:
𝑧 = sin(π‘₯ 2 ) cos(𝑦 2 )
where the ranges of π‘₯ and 𝑦 are:
βˆ’
πœ‹
πœ‹
≀π‘₯≀ ,
2
2
βˆ’πœ‹ ≀𝑦 β‰€πœ‹
Let βˆ†π‘₯ = βˆ†π‘¦ = 0.01. Provide a plot title and labels for the axes.
% Exam 2, ME 1020, Spring 2016
% Problem 1: Scott Thomas
clc
clear
close
N = 1000
t = linspace(0,4*pi,N);
y = sin(t);
for k = 1:N
if y(k) >= -0.5 & y(k) <= 0.5
z(k) = y(k);
else
z(k) = 0.0;
end
end
plot(t,z), xlabel('Time t'), ylabel('y(t)')
title('Problem 1: Exam 2, ME 1020, Spring 2016')
N =
1000
Published with MATLAB® R2012b
6 5 4 3 2 1 0
9 5 8 1 2 0 0
% Exam 2, ME 1020, Spring 2016
% Problem 2: Scott Thomas
clc
clear
close
t = 0;
dt = 0.01;
x = 5*t - 10;
y = 25*t^2 - 120*t + 144;
d = sqrt(x^2 + y^2);
k = 1;
while d > 15
x = 5*t - 10;
y = 25*t^2 - 120*t + 144;
d = sqrt(x^2 + y^2);
dplot(k) = d;
tplot(k) = t;
t = t + dt;
k = k + 1;
end
tmax = t - dt
plot(tplot,dplot), xlabel('Time t (seconds)')
ylabel('Distance d (meters)')
title('Problem 2: Exam 2, ME 1020, Spring 2016')
tmax =
1.6300
Published with MATLAB® R2012b
7 6 5 4 3 2 1 0
9 1 1 8 5 1 0 0
% Exam 2, ME 1020, Spring 2016
% Problem 3: Scott Thomas
clc
clear
close
N = 10000;
t = linspace(0,6*pi,N);
x = (1 + 0.25*cos(75*t)).*cos(t);
y = (1 + 0.25*cos(75*t)).*sin(t);
z = t + 2*sin(75*t);
plot3(x,y,z), xlabel('x'), ylabel('y'), zlabel('z')
title('Problem 3: Exam 2, ME 1020, Spring 2016')
grid
Published with MATLAB® R2012b
3 2 1 0
24 1 0 0
% Exam 2, ME 1020, Spring 2016
% Problem 4: Scott Thomas
clc
clear
close
x = -pi/2:0.01:pi/2;
y = -pi:0.01:pi;
[X,Y] = meshgrid(x,y);
Z = sin(X.^2).*cos(Y.^2);
mesh(X,Y,Z), xlabel('x'), ylabel('y'), zlabel('z')
title('Problem 4: Exam 2, ME 1020, Spring 2016')
grid
Published with MATLAB® R2012b
4 3 2 1 0
19 5 1 0