Jump to content

Numerical differentiation

Featured Replies

I have written the following MATLAB code

h = 10e-12;
f = @(x)cos(2*pi*x);

x = 0:.01:pi;

fd = (f(x+h)-f(x-h))/(2*h);

hold on
plot(x,f(x))
plot(x,fd, 'r')

 

The result is quite surprising.

fd, which is the derivative of f evaluated numerically, has an amplitude roughly 6 times larger than what the real derivative is.

Can anyone explain how this comes to happen?

The "real derivative" of [math]f(x)=cos(2\pi x)[/math] with respect to x is [math]-2\pi \sin(2\pi x)[/math]. 2*pi is a bit over six ...

  • Author

Yeah ok, that was kinda stupid. Reused a function from a sampled function, didn't notice the 2*pi. Thanks for clearing it up!

Archived

This topic is now archived and is closed to further replies.

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.