0

I am working on my homework, which is exercise 11.2b) from "Numerical Linear Algebra" by Trefethen.

The exercise asks me to fit a function $f(x) = \dfrac{1}{x}$ by a linear combination of the functions $e^x, \sin(x)$ and gamma function $\Gamma(x)$ on $[0,1]$ using Matlab. They also state that the following fact might be helpful: if $g(x)=\dfrac{1}{\Gamma(x)}$, then $g'(0)=1$.

I have written a Matlab code solving the least-square problem. I let $x$ is linspace(0,1,1000) and $A$ is matrix whose columns are $e^x, \sin(x), \Gamma(x)$. Then, the coefficients are computed by using this code on Matlab: $A\backslash b$. However, it turns out to be wrong. Moreover, if I did it this way, I did not use the fact they give me.

Can somebody please give me any idea on this? Any help is really appreciated!

  • 1
    If I understood the hint right, you need the Gamma function to counteract the singularity, so what remains is to fit $f(x)-\Gamma(x)$ to a linear combination of the other two functions. – Lutz Lehmann Oct 19 '23 at 06:53

1 Answers1

2

As Lutz Lehmann described, we need the Gamma function in order remove the singularity at $0$. The removal of the singularity is crucial for the success of this approximation. Most probably, you can use the hint for arguing that $\frac 1 x -\Gamma(x)$ is bounded for $x\to 0$. However, I was not able to use this hint properly. Instead I used the Laurent expansion of the Gamma function at $0$. In case, you are not familar with Laurant expansions, it is a similar representation as the Taylor expansion but we also allow negative indices in the sum. So as shown in here, we have the following representation $$\Gamma(x)=\frac 1 x -\gamma+ \mathcal O(x)\qquad \text{for }x\to 0,$$ while $\gamma = \Gamma'(1)\approx 0.57721$, also known as the Euler-Mascheroni-constant, and $\mathcal O$ denotes the Landau symbol. Thus, we get as direct consequence $$\lim_{x\to 0_+} \frac 1 x -\Gamma(x)= \lim_{x\to 0_+}\gamma+ \mathcal O(x)=\gamma \approx 0.57721.$$ Hopefully this solution is still satisfying, even though it uses more advanced information than stated in the exercise.

However, as stated in the comment of Lutz Lehmann we can now approximate $\frac 1 x -\Gamma(x)$ by $e^x$ and $\sin(x)$. As you sad in your post, I tried it as well with a least square routine. I got an absolute error of approx $0.1723$ and the following coefficients for $e^x$ and $\sin(x)$, respectively, $$0.625935943114312$$ $$-1.817300815880439.$$

Salfalur
  • 397
  • Thank you for your guidance. However, when I try $\dfrac{1}{0.001} - \Gamma(0.001)$ in MATLAB, the result is approx 0.57. And if I plot $\dfrac{1}{x} - \Gamma(x)$, then it is a decreasing functionm so, so I doubt that $\lim_{x\to 0_+} \frac 1 x -\Gamma(x)=0$. Do you think this makes sense? However, the coefficients for the least square is correct though. – hxllearnmath Oct 19 '23 at 17:29
  • hmmm your right that is not correct. We do not have $\frac 1 x -\Gamma(x)\to 0$, that does not hold. I see where I did the mistake. I Try to correct it tomorrow. – Salfalur Oct 19 '23 at 18:22
  • I suspect the way you're meant to use the hint is to find the coefficient of $\Gamma(x)$ that makes the difference between $\frac{1}{x}$ and the approximation finite, which you can do via l'Hospital's rule since you'll get to a limit like $\frac{\Gamma(x)}{\frac{1}{x}} = \frac{x}{g(x)}$. – ConMan Oct 19 '23 at 23:28