0

I need help finding the existence of roots within an interval $[a,b]$ of a difficult "ill-behaved" function $f(x)$ that is non-negative ($f(x) \ge 0$). So, one person suggested complex contour integration. However, I don't know what that means, nor where to start. Any help will be appreciated. Simply put, I want a way to find a way to tell if there are roots in between $[a,b]$, where $a$ and $b$ are real, positive numbers and both are greater than $1$. Any code should be written for Python 3.x (though JavaScript will also be accepted). A running-time analysis of the algorithm would be nice too. For example purposes, use: $$f(x)=10^3(\sin^2\left(\frac{15\pi}{x}\right)+\sin^2(\pi x)).$$

3 Answers3

3

The person who suggested complex analysis was likely thinking of the argument principle. Before using this method, please note that the factor of $10^3$ out front is irrelevant for finding zero. I will leave it off, therefore. The first thing to do is to find the derivative: \begin{align*} f(x)&=\sin^2\left(\frac{15\pi}{x}\right)+\sin^2(\pi x)\\ f'(x)&=-2\left(\frac{15\pi}{x^2}\right)\sin\left(\frac{15\pi}{x}\right)\cos\left(\frac{15\pi}{x}\right)+2\pi\sin(\pi x)\cos(\pi x). \end{align*} The trickest part of using contour integration for anything is choosing the contour. In this case, let us suppose we want to find the roots of $f$ in the interval $(a,b).$ An open interval works better for our purposes, because it would be difficult to find an enclosing contour that would not pick up more roots. We need a simple, closed contour such that this interval on the real line is entirely enclosed in it. So, let $\varepsilon>0.$ Then I choose the contour $\gamma$ given by the circle centered at $c=(b+a)/2$ of radius $r=(b-a)/2.$ We can parametrize this as: $$z=c+r\cos(\theta)+ir\sin(\theta)=c+re^{i\theta},\;\text{for}\;0\le\theta\le 2\pi. $$ This would yield $$dz=ire^{i\theta}\,d\theta. $$ Then the argument principle says that $$\int_\gamma\frac{f'(z)}{f(z)}\,dz=2\pi i(Z-P), $$ where $Z$ is the number of zeros inside $\gamma,$ and $P$ is the number of poles inside $\gamma.$ If $0\not\in(a,b),$ then we can confidently say $P=0,$ so that \begin{align*} Z&=\frac{1}{2\pi i}\int_\gamma\frac{f'(z)}{f(z)}\,dz \\ &=\frac{1}{2\pi i}\int_\gamma\frac{-2\left(\frac{15\pi}{z^2}\right)\sin\left(\frac{15\pi}{z}\right)\cos\left(\frac{15\pi}{z}\right)+2\pi\sin(\pi z)\cos(\pi z)}{\sin^2\left(\frac{15\pi}{z}\right)+\sin^2(\pi z)}\,dz. \end{align*} Then you would plug in the parametrization for $z$ and turn the crank - I'd recommend Mathematica, and you might need to do it numerically anyway.

Adrian Keister
  • 10,099
  • 13
  • 30
  • 43
  • Thank you for a beautiful answer! Just a few questions? What do you mean "plug in the parametrization for $z$ and turn the crank"? I was thinking on using Python (can adjust for my needs) and I want to focus on the real part of the complex contour integral (the one that gives you the number of roots). So, how would I do that? – ILoveMath Sep 26 '19 at 12:49
  • Also, how does $c$ play into this? – ILoveMath Sep 26 '19 at 13:26
  • This counts all roots, both real and complex. I think the OP just wants real roots, judging by the question. – DUO Labs Sep 28 '19 at 18:41
  • See this answer for a better contour: https://math.stackexchange.com/questions/3375852/real-contour-integration/3375894#3375894 This will help with Quote Dave's concern. By "plug in the parametrization and turn the crank", I mean substitute in $c+re^{i\theta}$ for $z$ and $ire^{i\theta},d\theta$ for $dz.$ The limits on the integral will be $0$ and $2\pi.$ Then you "turn the crank" by computing the integral. Finally, $c$ is the center of the circle that comprises the contour. – Adrian Keister Oct 01 '19 at 14:13
  • @AdrianKeister I may be wrong, but due to the fact that $\frac{d}{dz} \left(\frac{f'(z)}{f(z)} \right)=\log(f(z))$ and integration by substitution, wouldn't the integral just be $\int_{0}^{2\pi}\log(f(z))) ,d \theta$? – DUO Labs Oct 18 '20 at 00:22
  • @DUO: I think you have it reversed, don't you? $$\frac{d}{dz},\log(f(z))=\frac{f'(z)}{f(z)}.$$ Am I applying the argument principle incorrectly? I thought I had it right. – Adrian Keister Oct 18 '20 at 02:12
  • @AdrianKeister No, you're right. I meant to say, wouldn't the integral just be $\ln(f(z(2\pi)))-\ln(f(z(0)))$, where $z(\theta)$ is a function of $\theta$, as defined above? – DUO Labs Oct 18 '20 at 21:07
  • In complex land, it's not quite that simple. You get $2\pi i(Z-P),$ as the argument principle says. This is not real integration. – Adrian Keister Oct 19 '20 at 00:39
1

For your particular function, there's only one way you can get a root: for \begin{align*} \frac{15\pi}{x}&=k\pi\\ \pi x&=\ell\pi, \end{align*} for integers $k,\ell.$ We can rewrite as \begin{align*} \frac{15}{x}&=k\\ x&=\ell, \end{align*} so that we are looking for integers that divide evenly into $15.$ You will have zeros, therefore, precisely at $\pm 1, \pm 3, \pm 5,$ and $\pm 15.$

Adrian Keister
  • 10,099
  • 13
  • 30
  • 43
  • 1
    No, there aren't a lot of zeros between $[0,1].$ The $\sin^2(\pi x)$ takes care of that. There are precisely $8$ zeros in all, and I listed them in my solution. If you plot the function on $[-20,20],$ you'll see the zeros clearly. – Adrian Keister Sep 25 '19 at 02:53
  • Thank you for your answer. I suggest you add this last note to you answer, since the OP is interested in zeros between [0,1]. – NoChance Sep 25 '19 at 04:41
  • @NoChance: Actually, it looks more like the OP is interested in zeros on any sort of interval $[a,b].$ – Adrian Keister Sep 25 '19 at 14:03
  • 1
    That is fine, thanks for your answer and comments. – NoChance Sep 25 '19 at 14:50
  • @AdrianKeister That is right, I want to know if zeros exist between any interval, not having to know the roots. – ILoveMath Sep 25 '19 at 15:19
  • @ILoveMath: Well, if your function is at least continuous (in this case, any interval not containing zero will work), you can try the binary search algorithm. Problem is, if you don't choose your interval carefully, you won't get opposite signs for the function on either end. – Adrian Keister Sep 25 '19 at 15:25
  • Although binary search won't actually work for your example function, since it never changes sign! – Adrian Keister Sep 25 '19 at 15:31
  • @AdrianKeister That is true. Binary was the first thing that came to my mind. But wouldn't work. Hence, the question of complex contour integration. – ILoveMath Sep 25 '19 at 15:34
  • The person who suggested complex analysis is probably thinking about the argument principle: https://en.wikipedia.org/wiki/Argument_principle. The usefulness of the argument principle, I would think, would come down to whether you can easily identify the poles of the function. For your example, there are no poles, so that wouldn't be an issue. – Adrian Keister Sep 25 '19 at 15:45
  • @AdrianKeister Ok, seems interesting, but how can I use it for the example $f(x)$ (which I can then generalize). Even just specific steps, no code, would be very helpful. – ILoveMath Sep 25 '19 at 15:55
0

The estimation of the number of roots is trivial: check "many" points. Trying to approximate the possible roots (and checking that are roots) is the problem. Quotes form Newton Raphson Method for double roots (Henning Makholm an Ian):

The usual fast convergence of Newton-Raphson depends on the function having a nonzero derivative at the root.

The solution:

There is a modified Newton method which can detect proximity to a non-simple root and modify $f$ in such a way that quadratic convergence is recovered. If you know the order of the root is $n$, then you can use $$x_{k+1} = x_k - n \frac{f(x_k)}{f'(x_k)}.$$

  • @NoChance, see the edit. – Martín-Blas Pérez Pinilla Sep 24 '19 at 16:42
  • I appreciate your answer, however I think the link is gone. If you look at the graph of the function, it does have so many roots in [0,1] – NoChance Sep 24 '19 at 16:51
  • 1
    @NoChance, link works now. And you are right, looking the graph is usually enough. – Martín-Blas Pérez Pinilla Sep 24 '19 at 16:55
  • @Martín-BlasPérezPinilla If I remember correctly, doesn't the initial guess be "near" the root (whatever that means)? – ILoveMath Sep 24 '19 at 19:23
  • @ILoveMath, you are correct. Also be careful of the desired precision. For example: $f(0.0000019073486328)=0.0000000385464465$, if you are content with only 6 digits after the decimal point, this may be a root since it has 7 digits after the decimal. However, it is not an exact root (see Adrian's answer). – NoChance Sep 25 '19 at 04:47
  • @ILoveMath, I did not mention the term "dectect proximity"-Did I? My last comment was about numerical methods in general. One has to set an acceptable precision for the results to be meaningful. – NoChance Sep 25 '19 at 15:43
  • @NoChance Whoops, sorry, I meant that for Martin – ILoveMath Sep 25 '19 at 15:52
  • @Martín-BlasPérezPinilla Then what do you meant by "dectect proximity"? What's the difference of 100 iterations of the method for a guess off by $10^6$ verses one that is off by $10^3$? – ILoveMath Sep 25 '19 at 15:53