Approximate $e^{-x}$ function with sinusfunction combination

64 Views Asked by At

With the collection of sinus functions $a_1\sin(x)+a_2\sin(2x)+a_3\sin(3x)$ in $[0,\pi]$ I am to approximate $f(x)=e^{-x} $ in the same interval.

My first idea was to find the area under the 2nd function and try approximate that value by changing $a_1, a_2, a_3$ but obviously there's a billion ways to do that, without any of them looking like the desired function.

We have received a tip to use the trapezoidal rule, but I am unsure about how to do this. Hope someone can push me into the right direction.

2

There are 2 best solutions below

0
On

You are correct: there are many possible ways of defining what the "best fit" between two functions means.

The most common criterion for judging goodness-of-fit is least-square error (LSE). This means that if your approximating function is $g(x)$ and your target function is $f(x)$ and the interval is $[a, b]$ then you adjust the parameters in $g(x)$ to minimise the error function $$E=\int_a^b [f(x)-g(x)]^2 dx$$

For each free parameter $a_1, a_2, a_3...a_n$ of $g(x)$ you set $\partial E / \partial a_j =0$. You then have $n$ simultaneous equations to solve for the $n$ unknown parameters $a_1, a_2, a_3... a_n$.

When the error function $E$ has been minimised it is called the residual error $R$. This provides a figure of merit indicating the goodness of fit, so that $g(x)$ can for example be compared with an alternative fitting function $h(x)$.

In the case of discrete data points the integral becomes a summation and the method reduces to the usual least-squares regression.

0
On

As @sammy gerbil answered, let us consider three terms. This would give for $$\Phi=10 \,e^{2\pi}E$$ $$\Phi=e^{\pi } \left(-10 a_1+8 a_2-6 a_3+e^{\pi } \left(-8 a_2-6 a_3+5 \left(\pi a_1^2-2 a_1+\pi \left(a_2^2+a_3^2\right)\right)+5\right)\right)-5$$ Now, computing the partial derivatives $$\frac{\partial \Phi}{\partial a_1}=e^{\pi } \left(5 e^{\pi } (2 \pi a_1-2)-10\right)\implies a_1=\frac{1+e^{-\pi }}{\pi }$$ $$\frac{\partial \Phi}{\partial a_2}=e^{\pi } \left(e^{\pi } (10 \pi a_2-8)+8\right)\implies a_2=\frac{4(1- e^{-\pi })}{5 \pi }$$ $$\frac{\partial \Phi}{\partial a_3}=e^{\pi } \left(e^{\pi } (10 \pi a_3-6)-6\right)\implies a_3=\frac{3 \left(1+e^{-\pi }\right)}{5 \pi }$$

As you see, with this norm, it is very simple (one linear equation at the time).

The beauty is that, adding one more term does not change the previous and $$a_4=\frac{8(1- e^{-\pi })}{17 \pi }\qquad a_5=\frac{5 \left(1+e^{-\pi }\right)}{13 \pi }\qquad a_6= \frac{12(1-e^{-\pi })}{37 \pi }$$

Sooner or later, you will learn that this is the Fourier sine series expansion of $e^{-x}$ and that the coefficients are simply $$\color{red}{a_n=\frac{2 \left(1- (-1)^n e^{-\pi }\right) n}{\left(n^2+1\right)\pi}}$$