## Smooth approximations of 2^x

DSP, Plug-in and Host development discussion.
mtytel
KVRist
65 posts since 28 Jan, 2013 from Oakland
Z1202 wrote:
Tue Feb 19, 2019 1:19 am
mtytel wrote:
Mon Feb 18, 2019 12:08 pm
This time you keep the derivatives of the function evaluated at 2 half of the derivatives of the function evaluated at 1.
f'(1) = 2f'(2)
I got f^(n)(1) = 2^n f^(n)(2), probably that's the reason
Ah yeah should have been 2^n. Thanks for the catch.

mtytel
KVRist
65 posts since 28 Jan, 2013 from Oakland
juha_p wrote:
Tue Feb 19, 2019 12:41 pm
... but, how do I see/know if it's "smooth" or "smoother" than the one found in your linked PDF (equal degree approximation plotted as comparison)?
Smoothness of a function is about the continuity of derivatives of a function.

This approximation method is piecewise at every x integer. If you just linearly interpolate between the powers of two you'll end up with discontinuities in the first derivative at each integer. If you use the 2nd degree polynomial in the PDF, it makes the first derivative continuous but the second derivative is then discontinuous.

Your approximation has a (very slight) discontinuity in the first derivative (and subsequent derivatives) when you convert from the end of the window to the beginning (multiplied by two).

I think you can just add a tick after your function name to evaluate derivatives in desmos to see.

juha_p
KVRian
538 posts since 21 Feb, 2006 from FI
mtytel wrote:
Tue Feb 19, 2019 10:15 pm

Smoothness of a function is about the continuity of derivatives of a function.
...
Your approximation has a (very slight) discontinuity in the first derivative (and subsequent derivatives) when you convert from the end of the window to the beginning (multiplied by two).

I think you can just add a tick after your function name to evaluate derivatives in desmos to see.
Does this mean the error situation on each end (equal error is best option?)? I prepared another approximation (same technique as earlier) which has about equal error at -0.5 and 0.5 but, dunno if this is the way to go.

Code: Select all

``````double my_pow2x(double x){
double p = ((((0.00004190627326439316*x +
0.0006011232071797441)*x +
0.006938013800124066)*x +
0.06005662673708935)*x +
0.3465735902799904)*x +
1.0;
return p*p;
}
``````
Error comparison :

Code: Select all

``````                                   absolute error
x     std::pow(2,x)        my_pow2x       z1202_pow2x
-0.500   0.7071067812      7.535280e-08      3.893469e-06
-0.475   0.7194667900      5.650777e-08      3.690597e-06
...
+0.450   1.3660402568      3.837408e-08      8.234943e-06
+0.475   1.3899182198      5.425599e-08      8.073019e-06
+0.500   1.4142135624      7.535280e-08      7.786937e-06
``````
Regarding desmos, couldn't find other derivative related examples but this : g(x)=(d/dx)f(x) ... did you mean this ?

mtytel
KVRist
65 posts since 28 Jan, 2013 from Oakland
Here's an illustration on the smoothness difference:
https://www.desmos.com/calculator/3p8glvtjjk

Notice how the PDF's polynomial function and derivatives stay continuous through the piecewise transition.
Your function has a discontinuity in it when you piecewise it together. Even if you shift your polynomial to remove the discontinuity you'll have discontinuities in the first derivative.

Edit:
Though if you only want to evaluate on the -0.5 to 0.5 window your polynomial is better.

juha_p
KVRian
538 posts since 21 Feb, 2006 from FI
Thanks, especially the desmos example.
This is new subject for me so I wonder(ed) why less accuracy works better in this.