1 Problem 4-1: Differentiation The following data is given for a train Time t (sec) Position s (m) 10 75 20 175 30 360 35 480 40 600 Determine the velocity and acceleration of the train as a function of time. What is the velocity and acceleration of the train at t = 32 sec. Use the Lagrange interpolation to fit an interpolating polynomial. Plot the polynomial fit for the position, then plot the velocity and acceleration as functions of time. Use calculus for the hand solutions. For the computational solution use forward difference for the velocity and central difference for the acceleration with a discrete increment of Ah = 0.0001.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

I have made the MatLab code for this, but I don't know how to make the plots. I have provided the code below and just need assistance with the plotting.

% Problem 4-1 %
 
% A
x=[0,10,20,30,35,40];
y=[0,75,175,360,480,600];
 
% Using a second order Lagrange Polynomial for unequally spaced data
 
% Velocity for the starting point
back1=y(1)*((2*x(1)-x(2)-x(3))/((x(1)-x(2))*(x(1)-x(3))));
middle1=y(2)*((2*x(1)-x(1)-x(3))/((x(2)-x(1))*(x(2)-x(3))));
forward1=y(3)*((2*x(1)-x(1)-x(2))/((x(3)-x(1))*(x(3)-x(2))));
 
v1=back1+middle1+forward1;
 
% Velocity for the middle values 
back2_5=y(1:4).*((2.*x(2:5)-x(2:5)-x(3:end))./((x(1:4)-x(2:5)).*(x(1:4)-x(3:end))));
middle2_5=y(2:5).*((2.*x(2:5)-x(1:4)-x(3:end))./((x(2:5)-x(1:4)).*(x(2:5)-x(3:end))));
forward2_5=y(3:end).*((2.*x(2:5)-x(1:4)-x(2:5))./((x(3:end)-x(1:4)).*(x(3:end)-x(2:5)))); 
 
v2_5=back2_5+middle2_5+forward2_5;
 
% Velocity for the end point
back6=y(4)*((2*x(6)-x(5)-x(6))/((x(4)-x(5))*(x(4)-x(6))));
middle6=y(5)*((2*x(6)-x(4)-x(6))/((x(5)-x(4))*(x(5)-x(6))));
forward6=y(6)*((2*x(6)-x(4)-x(5))/((x(6)-x(4))*(x(6)-x(5))));
 
v6=back6+middle6+forward6;

% Finding total velocity (m/s)

v=[v1,v2_5,v6]
 
% Acceleration for the starting point
a_back1=v(1)*((2*x(1)-x(2)-x(3))/((x(1)-x(2))*(x(1)-x(3))));
a_middle1=v(2)*((2*x(1)-x(1)-x(3))/((x(2)-x(1))*(x(2)-x(3))));
a_forward1=v(3)*((2*x(1)-x(1)-x(2))/((x(3)-x(1))*(x(3)-x(2))));
 
a1=a_back1+a_middle1+a_forward1;
 
% Acceleration for the middle values 
a_back2_5=v(1:4).*((2.*x(2:5)-x(2:5)-x(3:end))./((x(1:4)-x(2:5)).*(x(1:4)-x(3:end))));
a_middle2_5=v(2:5).*((2.*x(2:5)-x(1:4)-x(3:end))./((x(2:5)-x(1:4)).*(x(2:5)-x(3:end))));
a_forward2_5=v(3:end).*((2.*x(2:5)-x(1:4)-x(2:5))./((x(3:end)-x(1:4)).*(x(3:end)-x(2:5)))); 
 
a2_5=a_back2_5+a_middle2_5+a_forward2_5;
 
% Acceleration for the end point
a_back6=v(4)*((2*x(6)-x(5)-x(6))/((x(4)-x(5))*(x(4)-x(6))));
a_middle6=v(5)*((2*x(6)-x(4)-x(6))/((x(5)-x(4))*(x(5)-x(6))));
a_forward6=v(6)*((2*x(6)-x(4)-x(5))/((x(6)-x(4))*(x(6)-x(5))));
 
a6=a_back6+a_middle6+a_forward6;

% Finding total acceleration (m/s^2)
 
a=[a1,a2_5,a6]
 
% B 
t=32; % Specified time value
p_32=((t-x(4))*(y(5)-y(4))/(x(5)-x(4)))+y(4); % Interpolating position at 32s
 
% Using a second order Lagrange Polynomial to determine the velocity at 32s
v32_back=y(4)*((2*t-t-x(5))/((x(4)-t)*(x(4)-x(5))));
v32_middle=p_32*((2*t-x(4)-x(5))/((t-x(4))*(t-x(5))));
v32_forward=y(5)*((2*t-x(4)-t)/((x(5)-x(4))*(x(5)-t)));
 
v_32=v32_back+v32_middle+v32_forward
 
% Using a second order Lagrange Polynomial to determine the acceleration at 32s
 
a32_back=v(4)*((2*t-t-x(5))/((x(4)-t)*(x(4)-x(5))));
a32_middle=v_32*((2*t-x(4)-x(5))/((t-x(4))*(t-x(5))));
a32_forward=v(5)*((2*t-x(4)-t)/((x(5)-x(4))*(x(5)-t)));
 
a_32=a32_back+a32_middle+a32_forward

 

1
Problem 4-1: Differentiation
The following data is given for a train
Time t (sec)
Position s (m)
10
75
20
175
30
360
35
480
40
600
Determine the velocity and acceleration of the train as a function of time. What is the velocity and acceleration of
the train at t = 32 sec. Use the Lagrange interpolation to fit an interpolating polynomial. Plot the polynomial fit for
the position, then plot the velocity and acceleration as functions of time. Use calculus for the hand solutions. For the
computational solution use forward difference for the velocity and central difference for the acceleration with a discrete
increment of Ah = 0.0001.
Transcribed Image Text:1 Problem 4-1: Differentiation The following data is given for a train Time t (sec) Position s (m) 10 75 20 175 30 360 35 480 40 600 Determine the velocity and acceleration of the train as a function of time. What is the velocity and acceleration of the train at t = 32 sec. Use the Lagrange interpolation to fit an interpolating polynomial. Plot the polynomial fit for the position, then plot the velocity and acceleration as functions of time. Use calculus for the hand solutions. For the computational solution use forward difference for the velocity and central difference for the acceleration with a discrete increment of Ah = 0.0001.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY