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
© Copyright 2026 Paperzz