Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

Wright State University Spring 2017

Department of Mechanical and Materials Engineering

ME 1020: ENGINEERING PROGRAMMING WITH MATLAB


FINAL EXAM
Open Book, Closed Notes
Create a Separate MATLAB Script File for Each Problem
Submit all MATLAB files to the Thumb Drive
Each MATLAB File Must Have the Following Header:

Problem 1 (5 Points): Calculate and plot the derivative of the following function over the range 𝑥 =
𝜋/10 to 9𝜋/10 using the Backward-Difference Method described in class (shown below). You must use a FOR
LOOP to solve this problem. Also, plot the original function on the graph.

𝑦 = cot(𝑥)

Problems 2, 3 and 4 are on back of this page.


Problem 2 (5 Points): Create a MATLAB script file to calculate and plot the function

9𝜋/10
𝑦 = 𝑦0 + ∫ −[csc(𝑥)]2 dx
𝜋/10

from 𝑥 = 𝜋/10 to 9𝜋/10 using the Trapezoidal Integration Method described in class (shown below). You
must use a FOR LOOP to solve this problem. Use the following value: 𝑦0 = 3.0777. Use 101 points from 𝑥 =
𝜋/10 to 9𝜋/10. Also plot the function being integrated −[csc(𝑥)]2 on the graph.

Problem 3 (5 Points): Create a MATLAB script file that uses the Euler Method discussed in class (shown
below) to solve the following differential equation. You must use a FOR LOOP to solve this problem. Plot the
solution from 0 ≤ 𝑡 ≤ 10 seconds.

𝑦̇ + 0.8𝑦 2 − 4.4 [exp(−0.008t)][sin(8𝑡)] = 0; 𝑦(0) = 8.0

Euler Method:

𝑑𝑦 𝑦𝑘+1 − 𝑦𝑘

𝑑𝑡 ∆𝑡

Problem 4 (5 Points): Using SIMULINK, solve the following differential equation, and plot 𝑦 from 0 ≤ 𝑡 ≤
10 seconds.

3𝑦̈ + 5𝑦̇ + 75𝑦 1.2 = 10 sin(2𝑡) , 𝑦̇ (𝑡 = 0) = −10, 𝑦(𝑡 = 0) = 15


Problem 1, ME 1020 Final Exam, Spring 2017
clc
clear
close all

N = 1000
x = linspace(pi/10,9*pi/10,N);
y = cot(x);
% dydxexact = -(csc(x)).^2;
for k = 1:N-1
dydx(k) = (y(k+1) - y(k))/(x(k+1) - x(k));
end

% plot(x,y,'k-',x(1:N-1),dydx(1:N-1),'k:',x,dydxexact,'k-.')
plot(x,y,'k-',x(1:N-1),dydx(1:N-1),'k-.')
xlabel('x'), ylabel('y'), title('Problem 1, ME 1020: Scott Thomas')
% legend('y = cot(x)','dy/dx Numerical','dy/dx Exact','Location','Best')
legend('y = cot(x)','dy/dx','Location','Best')

N =

1000

Published with MATLAB® R2016b


5 4 3 2 1 0
15 1 0 2 0 0
Problem 2, ME 1020 Final Exam, Spring 2017
clc
clear
close all

N = 101
x = linspace(pi/10,9*pi/10,N);
intyexact = cot(x);
y = -(csc(x)).^2;
inty(1) = 3.0777;
for k = 1:N-1
inty(k+1) = inty(k) + 0.5*(x(k+1) - x(k))*(y(k)+y(k+1));
end

% plot(x,y,'k-',x,inty,'k:',x,intyexact,'k-.')
plot(x,y,'k-',x,inty,'k:')
xlabel('x'), ylabel('y'), title('Problem 2, ME 1020: Scott Thomas')
% legend('-(csc(x))^2','y (Numerical)','y (Exact)','Location','Best')
legend('-(csc(x))^2','Integral','Location','Best')

N =

101

Published with MATLAB® R2016b


5 4 3 2 1 0
6 4 6 2 0 0
Problem 3, ME 1020 Final Exam, Spring 2017
clc
clear
close all

N = 10000;
dt = 0.001
y(1) = 8.0;
t(1)=0;
for k = 1:N
y(k+1) = y(k) + dt*(-0.8*(y(k))^(2) + 4.4*(exp(-0.008*t(k)))*(sin(8*t(k))));
t(k+1) = t(k) + dt;
end

plot(t,y)
xlabel('t'), ylabel('y'), title('Problem 3, ME 1020: Scott Thomas')

dt =

1.0000e-03

Published with MATLAB® R2012b

5 4 3 2 1 0
3 9 2 1 2 0
Problem 4:
5 4 3 2 1 0
6 4 3 0 5 0

You might also like