Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Matlab code Function Name: physics Inputs: ( double ) 1xM vector of time values

ID: 3741545 • Letter: M

Question

Matlab code

Function Name: physics

Inputs:

( double ) 1xM vector of time values

( double ) 1xM vector of velocity values

( double ) Degree that best fits velocity vs time data

Outputs:

None

Plot Outputs:

1. A plot with subplots of Velocity vs. Time, Numerical Derivative vs. Time, and Analytical Derivative vs. Time

Background:

You are in PHYS 2211, and you are tired of plotting velocity and acceleration graphs by hand. Luckily, you just learned how to plot and to find derivatives numerically and analytically in MATLAB.

Function Description:

Write a function that first plots the velocity values vs. time and then estimates and plots the acceleration in two different ways. Your function should do the following:

Create a 2x2 subplot.

Plot the velocity vs time graph in black in the top left position.

Approximate the acceleration data by finding the numerical derivative of the velocity. Plot

the numerical acceleration vs time graph in red in the top right position.

Now find the best-fit polynomial of the velocity data using the order given by the third input. Then, find a second approximation for the acceleration data by taking the analytical derivative of this polynomial and evaluating the derivative at the original time

values. Plot your derivative in green in the bottom right position.

Notes:

? The subplot in the bottom left position should not have a plot.

? Make the axes for all the subplots square.

? When plotting the numerical derivative, leave off the last time value, so the vector

lengths are the same.

Explanation / Answer

%code hasnt been debugged since no example output is provided, if any error occurs,please tell in comments

function physics(t,v,degree)
subplot(2,2,1)
plot(t,v,'k')
a=diff(v)./(diff(t));
subplot(2,2,2)
plot(t(1:end-1),a)
vpoly=polyfit(t,v,degree);
apoly=polyder(vpoly);
ap=polyval(apoly,t);
subplot(2,2,4)
plot(t,ap)