How can I find the smallest positive solution of an equation taking four digits of the fractional part

367 Views Asked by At

Find the smallest positive solution of $$\sum_{n=0}^{\infty}\frac{(-x)^n}{(n!)^2}=0$$ taking four digits of the fractional part

2

There are 2 best solutions below

0
On

Rewrite f(x) as $$ f(x) = \sum\limits_{n\, = \,0}^\infty {\frac{{\left( { - 1} \right)^{\,n} }} {{\left( {n!} \right)^{\,2} }}x^{\,n} } = f(x,q) + R(x,q) = \sum\limits_{n\, = \,0}^q {\frac{{\left( { - 1} \right)^{\,n} }} {{\left( {n!} \right)^{\,2} }}x^{\,n} } + \sum\limits_{n\, = \,q + 1}^\infty {\frac{{\left( { - 1} \right)^{\,n} }} {{\left( {n!} \right)^{\,2} }}x^{\,n} } $$ Consider that the ratio of the terms, excluding $(-1)^n$, is $$ r = \frac{x} {{\left( {n + 1} \right)^{\,2} }}\quad \Rightarrow \quad r < 1\quad \left| {\;0 \leqslant x < } \right.\left( {n + 1} \right)^{\,2} $$ so that, for $x$ positive and less than $(n+1)^2$, the terms are decreasing in absolute value, and being the sign alternated we have that $$ f(x,2n - 1) < f(x,2n + 1)<\dots < f(x)<\dots < f(x,2n+2) < f(x,2n ) $$ Then we can start with $$ f(x,2) = 1 - x + \frac{{x^{\,2} }}{4} $$ and find that its (double) root is $$ x_{\,0,2} = 2 < \left( {2 + 1} \right)^{\,2} $$ which is within the range for $r<1$. Therefore we can feed this value to $f(x,3)$, to find a negative value, wherefrom we can just use the secant method ($f'(x,3)$ is negative) to estimate $x_{\,0,3}$, in case iterating it some times. But of course you can also use Newton's method: the 1st and 2nd derivatives are practically.. "already there" . Then feed it $f(x,4)$ , and continue till the difference of the roots is less than the given threshold (i.e. <0.00001, to assure that the result is accurate to the fourth decimal digit).
And a sketch is always of great help:

Polinomio tronco

0
On

As was demonstrated in the answer by G.Cab, there is a root between $0$ and $2$ based on opposite signs established using $f(x,3)$ and $f(x,4)$. This allows to employ bracketing methods such as regula falsi/false position method.

Since the most important property is the sign of the function value, one only needs to compute partial sums of the alternating series until a definite sign is established. The secant using the approximate function values will still be useful enough for the next iterate.

Both together are implemented in this code:

#include<math.h>
#include<stdio.h>


long double f(long double x) {
  long double sum=1-x, term=-x;
  int n=2;
  while(1+term != 1) {
    term *= -x/(n*n); sum += term;
    if( ((n%2==0)?sum:-sum) < 0 ) break;
    n++;
  }
  printf("\nf(% .8Lf,[%2d])=% .8Lf (f(...,[%2d])=% .8Lf)", x,n,sum,n-1,sum-term);
  return sum;
}

int main(void) {
    const int dp = 5;
    long double eps=0.5*powl(10,-dp);
    int i=0;
    long double a=0, fa = f(a);
    long double b=2, fb = f(b);

    if(signbit(fb)==signbit(fa)) {
        printf("Warning, initial values do not have opposite sign!\n");
    }

    do {
        long double c=(a*fb-b*fa)/(fb-fa), fc = f(c);

        if( signbit(fc)!=signbit(fa) ) {
            b=a; fb=fa;
            a=c; fa=fc;
        } else {
            a=c; fa=fc;
            fb *= 0.5;
        }
        i++;  
    } while(fabsl(b-a)>eps);

    printf("\ngoal reached after %d iterations\n",i);

    return 0;
}

with output

f( 0.00000000,[ 2])= 1.00000000 (f(...,[ 1])= 1.00000000)
f( 2.00000000,[ 4])=-0.19444444 (f(...,[ 3])=-0.22222222)
f( 1.67441860,[ 4])=-0.09025591 (f(...,[ 3])=-0.10390280)
f( 1.53580328,[ 4])=-0.03709625 (f(...,[ 3])=-0.04675498)
f( 1.42972818,[ 3])= 0.00012083 (f(...,[ 2])= 0.08130249)
f( 1.43007256,[ 5])= 0.00680985 (f(...,[ 4])= 0.00722521)
f( 1.45846639,[ 4])=-0.00500612 (f(...,[ 3])=-0.01286142)
f( 1.44643666,[ 6])=-0.00027582 (f(...,[ 5])=-0.00029349)
f( 1.44521038,[ 5])= 0.00023604 (f(...,[ 4])= 0.00067386)
f( 1.44577586,[ 7])= 0.00000890 (f(...,[ 6])= 0.00000942)
f( 1.44581590,[ 6])=-0.00000787 (f(...,[ 5])=-0.00002549)
f( 1.44579710,[ 8])=-0.00000026 (f(...,[ 7])=-0.00000028)
f( 1.44579591,[ 7])= 0.00000024 (f(...,[ 6])= 0.00000076)
goal reached after 11 iterations