Approximation of the cosine by gaussian functions

2k Views Asked by At

Choosing the parameters $\alpha$, $\omega$, and $\phi$ carefully, the function

$$f(x) = \alpha \cos(\omega x + \phi)$$

can be almost perfectly approximated (at least visually) by the sum of two gaussian functions

$$g(x) = e^{-x^2} -e^{-(x-1)^2}$$

in the interval $x \in [-0.24,1.24]$:

enter image description here

Roughly guessed values are

$\alpha \approx 0.7304$

$\omega \approx 2/3\ \pi$

$\phi \approx 0.5$

I wonder which closed formulas - only containing natural numbers and standard constants like $\pi, e$, or the golden ratio $\varphi$ - might yield the optimal parameters. Maybe the formulas for $\omega$ and $\phi$ in these approximations are already exact?

[Note, that $\alpha \approx 0.7304$ is nothing but the maximal value of $g(x)$. So it can be obtained by finding $x_0$ with $g'(x_0)=0$ and $g(x_0)>0$ – which is approx. $-0.24$ – and calculating $g(x_0)$.]

3

There are 3 best solutions below

7
On

The answer will depend on on your definition of approximation. In general setting, you take a (semi)norm $\|\cdot\|$ in the space of functions over your interval $[a,b]=[-0.24,1.24]$ and then minimize the norm of the difference $$\left\|e^{-x^2} -e^{-(x-1)^2} - \alpha\cos(\omega x+\phi)\right\|$$ with respect to parameters $\alpha$, $\omega$, and $\phi$.

Depending on your choice of the norm, this minimisation problem will be easier/harder to solve. I'd say that the easiest one is the $L^2$ norm, followed by $L^\infty$ norm and $L^1$ norm.

For obvious reasons you will never obtain an exact approximation - trigonometric functions are linearly independent with gaussian functions.

On a side note, you can even relax the problem to use a distance instead of a norm, but it will only add complexity to the problem.

2
On

There is probably no answer.

Because the "optimal" constants are solutions of transcendental equations, and probably have no closed-form expression in terms of the "standard" constants.

Then you can get closer and closer to the desired values with silly formulas such as

$$\frac{7304\pi}{10000\pi}$$ giving arbitrary precision approximations without ever reaching the exact value.

1
On

As it was already said in the previous answers and comments, there's no 'ideal' approximation, however, there are some ways to estimate the parameters the OP wants (but not a unique way and never exactly!).

Which is why this post is not as much an attempt to answer the question as posed (since the OP does not clarify what "optimal" means), but just some fun with the problem at hand.


First let's simplify the problem: it's very easy to see that $g(x)=0$ at $x=1/2$.

Which means we can set:

$$\alpha \cos (\omega/2+\phi)=0$$

And (up to addition of $\pi n$ for some integer $n$):

$$\phi=\frac{\pi}{2}-\frac{\omega}{2}$$

$$\alpha \cos (\omega x+\phi)=-\alpha \sin \left(\omega\left(x-\frac12 \right) \right)$$

Now it makes sense to set $t=x-\frac12$ and rewrite both functions:

$$F(t)=-\alpha \sin (\omega t)$$

$$G(t)=\exp \left(-\left(t+\frac12 \right)^2 \right)-\exp \left(-\left(t-\frac12 \right)^2 \right)$$

Using the values of $\alpha, \omega$ the OP provided, we obtain the following plot:

enter image description here

With the error (note that it's zero at $x=0,\pm 1/2$ because we defined $\phi$ that way):

enter image description here

I note that since the OP took $\alpha$ to be the maximal value of $g(x)$, it doesn't have an explicit form, because it represents:

$$\alpha=g(x_m)=g(-0.2717023192091\dots)$$

Where $x_m$ is the negative root of:

$$x(1-e^{-(2x-1)})=1$$

Once we chose $\alpha$ this way, we obtain just a one parameter optimization problem (for $\omega$). Which can be solved in a miriad of ways.


I would like to propose one method, which is not without its own charm.

  • One of the many ways to estimate the parameters is to use the first few terms of the Taylor series for $t \to 0$:

$$F(t)=-\alpha \omega \left(t-\frac{\omega^2 t^3}{6}+\frac{\omega^4 t^5}{120}-\frac{\omega^6 t^7}{5040}+ \dots \right)$$

$$G(t)=-\frac{2}{\sqrt[4]{e}} \left(t-\frac{5 t^3}{6}+\frac{41 t^5}{120}-\frac{461 t^7}{5040}+ \dots \right)$$

The series are quite similar (the denominators are all in the form of $(2k+1)!$), though of course there's no way to make them equal for all $t$.

It makes sense to set:

$$\alpha \omega=\frac{2}{\sqrt[4]{e}}$$

Now we again obtain a one parameter problem.

(1) If we pick $\alpha$ from the OP, them $\omega$ is already defined, $\omega \approx 2.13256556$, which is slightly greater than $2 \pi /3 \approx 2.0943951$ and gets the error in the form:

enter image description here

(2) Another simple method to get some values for the parameters would be to equate the first two terms, then we obtain:

$$\omega=\sqrt{5} \approx 2.23607$$ $$\alpha=\frac{2}{\sqrt[4]{25e}} \approx 0.69658$$

Quite different from the OP's values, but that's to be expected. The error is small for small $t$ but increases for larger $t$:

enter image description here

enter image description here

(3) Yet another way is to use the truncated Taylor series and the least squares method, i.e. findins such $\omega$ that:

$$\min \left[ \int_a^b \left( F(t)-G(t) \right)^2 dt \right]$$

For convenience, we choose $a=-1$, $b=1$ and truncate the series at $t^5$, then we are searching for the solution to:

$$\int_{-1}^1 \left( \frac{\omega^2-5}{6} t^3-\frac{\omega^4-41}{120} t^5 \right)^2 dt=\frac{63 \omega^8 - 3080 \omega^6 + 49834 \omega^4 - 269720 \omega^2 + 464503}{4989600}$$

Searching for the global minimum of the above expression (by taking a derivative) we find that it's one of the roots of the equation:

$$63 \omega^6 - 2310 \omega^4 + 24917 \omega^2 - 67430=0$$

It's a cubic equation for $\omega^2$, however the explicit form of the roots is not nice, so it's better to write an approximation:

$$\omega=2.018371488396495 \dots$$

$$\alpha=0.7717120337 \dots$$

enter image description here

This approximation seems worse, but that's because we chose a larger interval, and only considered 3 terms of the Taylor series.

We can certainly imporve the approximation according to the proposed criterion.


Some concluding remarks. The choice for all $3$ parameters is still mostly arbitrary and strongly depends on the optimization criteria we choose. So all of the above is just an example.


Also. This problem has absolutely nothing to do with the golden ratio.