{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

39. Numerical differentiation

39. Numerical differentiation - Numerical Differentiation...

Info icon This preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
©2009 by L. Lagerstrom Numerical Differentiation For an introduction to the basic concepts, see the associated video clip The diff function The backward difference (BD) approximation for a noisy signal The central difference (CD) approximation for a noisy signal Finding acceleration using a forward difference (FD) approximation Difference approximation vs. curvefitting
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Matlab code Command window display ©2009 by L. Lagerstrom The diff Function %The diff function will calculate %the differences between each %element in a row vector. %Some sample data x = [ 0 5 10 15 20 25] y = [20 30 25 50 80 100] %Calculate differences delta_x = diff(x) delta_y = diff(y) %Do rise/run calculations deriv = delta_y./delta_x %Note that the third value, for %example, in deriv (the value 5) may %be taken as a forward difference %approximation for the third data %point (10,25), or a backward differ- %ence approximation for the fourth %data point (15,50). Either way, %the rise/run = (50-25)/(15-10) = 5. x = 0 5 10 15 20 25 y = 20 30 25 50 80 100 delta_x = 5 5 5 5 5 delta_y = 10 -5 25 30 20 deriv = 2 -1 5 6 4
Image of page 2
Matlab code Command window display ©2009 by L. Lagerstrom The diff Function, cont. %Redisplay code from previous slide %to make another point x = [ 0 5 10 15 20 25] y = [20 30 25 50 80 100] delta_x = diff(x) delta_y = diff(y) deriv = delta_y./delta_x %These rise/run results may be taken %as either forward difference (FD) %approximations or backward differ- %ence (BD) approximations. If we %choose to do FD approximations, then %the five values in deriv are FD %approximations for the first five %data points in the (x,y) data set. %(The last point, i.e. (25,100), does %not have an FD approx., because %there's no forward point to go to.) %If we choose BD approximations, then %the five values in deriv are BD %approximations for the second %through last point in the (x,y) set. x = 0 5 10 15 20 25 y = 20 30 25 50 80 100 delta_x = 5 5 5 5 5 delta_y = 10 -5 25 30 20 deriv = 2 -1 5 6 4
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Matlab code Figure window display ©2009 by L. Lagerstrom The BD Approximation for a Noisy Signal %Imagine that we have measured a sinu- %soidal signal with some noise in it. %We'll simulate this with 50 (t,x) %data points, created by adding Gaus- %sian random values with a standard %deviation of 0.025 to a sine function %with a max amplitude of 1: t = linspace(0,2*pi,50); x = sin(t) + 0.025*randn(1,50); %Plot the data to check it out plot(t,x,'.') title('Noisy Sine Signal') xlabel('t') ylabel('x') axis([0 2*pi -2 2]) %We see that though there's a little %noise in the data, it's easy to %identify it as a sinusoidal curve.
Image of page 4
Matlab code Figure window display ©2009 by L. Lagerstrom The BD Approximation for a Noisy Signal, cont.
Image of page 5

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern