In: Mechanical Engineering
1.Write down the fplot( ) command used to generate a straight line formed by two (x, y) points: (-3, 5) and (3, 8). Plot the line from -5 ≤ x ≤ 5. Show your derivation of the line equation.
2. [15pts] The position x as a function of time of a particle that moves along a straight line is given by
a. [3pts] Derive the expressions for the velocity and acceleration of the particle
Make plots of the position, velocity, and acceleration as a functions of time for 0 ≤ t ≤ 15 sec following the instructions below.
b. [6pts] Using plot( ), plot the position, velocity, and acceleration on a single plot window using black solid line, green dash line, and yellow dash-dot line, respectively. Show the plot in Figure 1. Use the line width of 2. Include the following title in bold face: “Motion profile of a particle between 0 ≤ t ≤ 15 sec”. Include proper legend and axis labels with units. Show grid lines. All formatting must be done inside your code and not from the Figure Editor.
c. [6pts] Using subplot, plot the position, velocity, and acceleration vs time in 3 separate plots arranged in a single column. Show the subplot in Figure 2. Include the following title in bold face above the top-most plot: “Position, velocity and acceleration profile of a particle”. Show grid lines and proper axis labels on all your plots. All formatting must be done inside your code and not from the Figure Editor.
The two points are given by (-3,5) and (3,8)
The equation of line joining two points is given by y-y1=(y2-y1)/(x2-x1)*(x-x1)
=> y-5=(8-5)/(3+3)*(x+3)
=> 2y-10=x+3
=> y=(x+13)/2 (Our Line Equation)
Using the command fplot(@(x) (x+13)/2), I got the following plot
Here suppose x is taken as time and y is taken as position of particle
rewriting this equation in terms of position and time, we get
x=(t+13)/2;
The velocity of a particle is the differentiation of position with respect to time
=> we get velocity v=dx/dt=1/2;
the acceleratio of a particle is the differentiatio of velocity with respect to time
=> we get acceleration a=dv/dt=0;
plotting position, velocity and acceleraton with respect to time in MATLAB, we get
and the Matlab code is
clc
clear
t = linspace(0,15);
x=(t+13)/2;
v=1/2+0*t;
a=0+0*t;
plot(t,x,'-k','LineWidth',2,'markerfacecolor','k');
hold on
plot(t,v,'--g','LineWidth',2,'markerfacecolor','g');
hold on
plot(t,a,'-.y','LineWidth',2,'markerfacecolor','y');
axis on;
grid on;
title('\fontsize{16}\fontname{Times New
Roman}Motion profile of a particle between 0<=t<=15
sec');
xlabel('\fontsize{12}\fontname{Times New
Roman}time(sec)');
ylabel('\fontsize{12}\fontname{Times New
Roman}position(m) velocity(m/s) acceleration(m/s^2)');
legend('position','velocity',
'acceleration');
axis([0 15 0 inf]);
Using subplot, I got the following figure
and the Matlab code is
clc
clear
title('Position, velocity and acceleration profile of a
particle')
subplot(3,1,1)
t = linspace(0,15);
x=(t+13)/2;
plot(t,x,'-k','LineWidth',2,'markerfacecolor','k');
axis on;
grid on;
title('\fontsize{12}\fontname{Times New Roman}"Position, velocity
and acceleration profile of a particle”');
xlabel('\fontsize{12}\fontname{Times New Roman}time(sec)');
ylabel('\fontsize{12}\fontname{Times New Roman}position(m)');
subplot(3,1,2)
t = linspace(0,15);
v=1/2+0*t;
plot(t,v,'--g','LineWidth',2,'markerfacecolor','g');
axis on;
grid on;
xlabel('\fontsize{12}\fontname{Times New Roman}time(sec)');
ylabel('\fontsize{12}\fontname{Times New Roman}velocity(m/s)');
subplot(3,1,3)
t = linspace(0,15);
a=0+0*t;
plot(t,a,'-.y','LineWidth',2,'markerfacecolor','y');
axis on;
grid on;
xlabel('\fontsize{12}\fontname{Times New Roman}time(sec)');
ylabel('\fontsize{12}\fontname{Times New
Roman}acceleration(m/s^2)');