Message Boards Message Boards

0
|
3654 Views
|
3 Replies
|
2 Total Likes
View groups...
Share
Share this post:

[?] Avoid problem with Interpolation function for higher order derivatives?

Posted 5 years ago

I have a function $C_0(x)=e^{-(x-2.5)^2/2.0}$ which is differentiable to infinite order. I want to approximate the function with Interpolation such that it is smooth until 10th derivative. Here is the code I use

Nx = 512; u0 = 0.0; uN = 5.0; du = (uN - u0)/Nx;
ugrid = du Range[0, Nx];
C0 = Exp[-(# - Lx/2)^2/2] & /@ ugrid;
C0Poly = Interpolation[Transpose[{ugrid, C0}], InterpolationOrder -> 10]

However, when I drew the derivatives, it looks smooth only up to 6th order. Here's how the 7th derivative looks like

Plot[(C0Poly^(7))[x],{x,0,Lx}]

enter image description here

The higher order derivatives are worse. I just want to know how to improve the smoothness of the approximated function.

POSTED BY: Rui Ma
3 Replies

Rui,

The problem is that Derivative is a noisy operation. I improved things by making the numbers use infinite precision and converted them to 30 digits of precision before interpolation. Try Experimenting with this:

Manipulate[Nx = 2^pow; u0 = 0; uN = 5; du = (uN - u0)/Nx;
 ugrid = du Range[0, Nx];
 C0 = Exp[-(# - Lx/2)^2/2] & /@ ugrid; 
 exact[x] = D[Exp[-(x - Lx/2)^2/2], {x, der}];
 C0Poly = 
  Interpolation[N[Transpose[{ugrid, C0}], 30], 
   InterpolationOrder -> 10];
 exact[x] = D[Exp[-(x - Lx/2)^2/2], {x, der}];
 Plot[{Derivative[der][C0Poly][x], exact[x]}, {x, 0, Lx}, 
  PlotRange -> All, 
  ImageSize -> Large], {{pow, 9, 
   Dynamic["Points: " <> ToString[2^pow]]}, 4, 15, 
  1}, {{der, 9, Dynamic["Deriv: " <> ToString[der]]}, 1, 12, 1}, 
 ContinuousAction -> False, LabelStyle -> "Text"]

It will show you that the number of points matters and actually fewer points will be smoother. For some reason (which I have not yet figured out) the derivative is better if you use a power of two in the number of points. The number of intervals must interact with the method of interpolation. I hope this helps.

Regards,

Neil

POSTED BY: Neil Singer
Posted 5 years ago

Neil,

Thank you so much! This helps a lot. Though I didn't get it why fewer points give smoother interpolation, 256 points seem to work properly for my purpose.

Best regards, Rui

POSTED BY: Rui Ma

I will venture a guess that the more points, the greater the likelihood that the degree ten (or so) local polynomial interpolants have spikes in small regions. This can worsen the noisiness noted by @NeilSinger.

Again, this is just a guess.

POSTED BY: Daniel Lichtblau
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract