Marmara University

Marmara University
Faculty of Engineering
Mechanical Engineering Department
Fall 2011 - CSE 123.2 - Laboratory Session 7
1. Plot the following functions on the same graph for x values from –π to π, selecting
spacing to create a smooth plot:
2. Write a Matlab function that will generate a plot of a second order polynomial whose
coefficients are input by the user.
3.
h(t )  vt sin  
1 2
gt , x(t )  vt cos 
2
a. Suppose a ball is thrown with a velocity v=10 m/s at an angle of 35o . Use Matlab
to compute how far it will go and how long it will take to hit the ground.
b. Use the velocity and angle data from part a to plot ball's trajectory.
c. Plot trajectories for v=10 m/s corresponding to five values of the angle: 20, 30, 45,
60, 70.
d. Plot the trajectories for 45 degree angle corresponding to five values of the initial
velocity v: 10, 12,14, 16 and 18 m/s.
4.
5.
6. Assume that a sample of an ideal gas contains 1 mole of molecules at a temperature of
273 K. Remember the ideal gas relation
PV =nRT
and R= 8.314 L.kPa/mol.K
a. How does the volume of this gas vary as its pressure varies from 1 to1000 kPa?
Plot pressure versus volume for this gas on a appropriate set of axes.
b. Suppose that the temperature of gas is increased to 373 K. how does the volume of
this gas vary with pressure now? Plot pressure versus volume for this gas on the
same set of axes as part a. Use dashed blue line.
Include a bold face title and x and y axis labels on the plot, as well as legends for each
line.
%ideal gas
n = 1;
R = 8.314;
T = 273;
P = 1:0.1:1000;
V = (n*R*T)./P;
figure(1)
plot(P,V, 'r-','LineWidth',2); loglog(P,V, 'r-','LineWidth',2);
title('\bf Volume vs Pressure in an Ideal Gas');
xlabel('\bf Pressure (kPa)');
ylabel('\bf Volume (L)');
grid on;
hold on;
% increase temperature
T=373;
V = (n*R*T)./P;
figure(1)
plot(P,V, 'b--','LineWidth',2); loglog(P,V, 'r-','LineWidth',2);
hold off;
legend ('T = 273 K','T = 373 K');
7. The output power produced by a rotating motor is given by the equation
P= tind wm
where tind is the induced torque on the shaft in N.m, wn is the rotational speed of the shaft
in radians per second and P is in Watts.
assume that
wm  188.5(1  e 0.2t ) rad / s and
t ind  10e 0.2t N .m
Plot the torque, speed and power supplied versus time for 0  t  10 s. Label your plot
properly. Create two plots, one with the power displayed on a linear scale and one with
the output power displayed on a logarithmic scale. Time should always be displayed on a
linear scale.
% motor power
t
= 0:0.1:10;
w
= 188.5 * (1-exp(-0.2.*t));
tau = 10*exp(-0.2.*t);
P=w.*tau;
figure(1)
subplot(2,1,1)
plot(t,w)
ylabel('\bf Rotational Speed (rad/s)');
grid on
subplot(2,1,2)
plot(t,tau)
grid on
xlabel('\bf Time (s)');
ylabel('\bf Torque (N.m)');
figure(2)
plot(t,P)
title('\bf Electric Motor Power (W)');
xlabel('\bf Time (s)');
ylabel('\bf Power (W)');
grid on
figure(3)
semilogy(t,P)
title('\bf Electric Motor Power (W)');
xlabel('\bf Time (s)');
ylabel('\bf Power (W)');
grid on
8. The height h(t) and horizontal distance x(t) travelled by a ball thrown at an angle A with a
speed v are given by
h(t )  vt sin A 
1 2
gt
2
x(t )  vt cos A
At Earth's surface the acceleration due to gravity is g = 9.81 m/s2.
a. Suppose the ball is thrown with a velocity v = 10 n:/s at an angle o f35°. Use MATLAB
to compute how high the ball will go, how far it will go, and how long it will take to hit
the ground.
b. Use the values of v and A given in part a to plot the ball 's trajectory; that is, plot h
versus x for positive values of h.
c. Plot the trajectories for v = 10 m/s corresponding to five values of the angle A: 20°,
30°, 45°, 60°, and 70°.
d. Plot the trajectories for A = 45° corresponding to five values of the initial velocity v:
10, 12, 14, 16 and 18 m/s.
g = 9.81;
% Part a
v = 10;A = 35*(pi/180);
t_hit = (2/g)*v*sin(A);
t = [0:t_hit/1000:t_hit];
h = v*t*sin(A)-.5*g*t.^2;
[peak_height,i_peak] = max(h);
t_peak = i_peak*t_hit/1000;
peak_height
distance = v*t_hit*cos(A)
t_hit
% Part b
x=v*t*cos(A);
plot(x,h),xlabel(‘Distance (meters)’),ylabel(‘Height (meters)’)
%part c
g = 9.81;
v = 10;A = [20,30,45,60,70]*(pi/180);
t_hit = (2/g)*v*sin(A);
t = [0:max(t_hit)/1000:max(t_hit)];
sA = sin(A);
cA = cos(A);
r = .5*g*t.^2;
X = v*[t*cA(1),t*cA(2),t*cA(3),t*cA(4),t*cA(5)];
r = .5*g*t.^2;
R = [r,r,r,r,r];
Q = v*[t*sA(1),t*sA(2),t*sA(3),t*sA(4),t*sA(5)];
H = Q-R;
max_x = v*t_hit(3)*cA(3);
plot(X,H),axis([0 max_x 0 max(max(H))]),xlabel(‘Distance
(m)’),...
ylabel(‘Height (m)’),gtext(‘20 deg’),gtext(‘30 deg’),...
gtext(‘45 deg’),gtext(‘60 deg’),gtext(‘70 deg’)
%part d
g = 9.81;A = 45*(pi/180);
v = [10:2:18];
t_hit = (2/g)*v*sin(A);
t = [0:max(t_hit)/1000:max(t_hit)]’;
r = .5*g*t.^2;
X = cos(A)*[t*v(1),t*v(2),t*v(3),t*v(4),t*v(5)];
R = [r,r,r,r,r];
Q = sin(A)*[t*v(1),t*v(2),t*v(3),t*v(4),t*v(5)];
H = Q-R;
plot(X,H),axis([0 max(max(X)) 0 max(max(H))]),xlabel(‘Distance
(m)’),...
ylabel(‘Height (m)’),gtext(‘10 m/s’),gtext(‘12 m/s’),...
gtext(‘14 m/s’),gtext(‘16 m/s’),gtext(‘18 m/s’)
9. The following functions describe the oscillations in electrical circuits and the vibrations of
machines and structures. Plot these functions on the same plot. Because they are similar, decide
how best to plot and label them to avoid confusion.
x(t )  10e 0.5t sin(3t  2)
y (t )  7e 0.4t cos(5t  3)
t = [0:.02:10];
x = 10*exp(-.5*t).*sin(3*t+2);
y = 7*exp(-.4*t).*cos(5*t-3);
plot(t,x,t,y,’:’),xlabel(‘t’),ylabel(‘x(t),y(t)’),legend(‘x(t)’,
’y(t)’)