Note: This writeup was under the Newton-Raphson method node, but since it was found out that my method was not Newton-Raphson it came here. The method is some variation of mine which yields good results in the style of the Newton-Raphson method.

Sometimes, while trying to solve some problems, we are faced with equations that cannot (with moderate knowledge at least) be solved with classic mathematics. Here's an example of such a problem:

A farmer has a round corn field and, oddly enough, wants to tie his donkey to the fence, so that the donkey can only pasture from half the field (half, meaning half the field's surface). What should be the length of the rope that he will use?

So, at about the end of the solution, we have this equation to solve: K + sinK - K*sinK - π/2 = 0. At least I do not know any way to solve such an equation which has both an angle and its sine. So, I wrote a simple C program, so that I could help the poor farmer.

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

float f(float x){
  float pi;
  pi = acos(-1);
  return x + sin(x) - x*sin(x) - pi/2;
}

int main(){

  float a, b, tmp;
  float x;
  float step, pres, res;
  float x_good, f_good;
  float pi;
  float ultim_pres = 0.0000001;
  int digits, larg_dig=0;
   
  pi = acos(-1);

  step = 0.1;
  a = 0.0;
  b = 2*pi;
  
  do{
   pres = 9999999.0;
   for(x=a; x <= b; x += step){
     res = f(x);
     if (fabs(res) < pres){
       x_good = x;
       pres = fabs(res);
     }
   } 
   digits = -1.0*log(step)/log(10);
   if (digits > larg_dig){
     printf("Best solution is %.10f, with step %.10f, so only first %d decimal digit(s) are OK.\n\n",
       x_good, step, digits);
     larg_dig = digits;
   }

   step /= 2.0;
   a = x_good - x_good*5/100; b = x_good + x_good*5/100;;
   if (a > b){
     tmp = a;
     a = b;
     b = tmp;
   }
  } while (pres > ultim_pres);  
  return 0;
  
}

So, after some seconds, the program yields:

Best solution is 2.4749996662, with step 0.0500000007, so only first 1 decimal digit(s) are OK.
Best solution is 2.4785645008, with step 0.0062500001, so only first 2 decimal digit(s) are OK.
Best solution is 2.4800722599, with step 0.0007812500, so only first 3 decimal digit(s) are OK.
Best solution is 2.4800074100, with step 0.0000976563, so only first 4 decimal digit(s) are OK.
Best solution is 2.4800443649, with step 0.0000061035, so only first 5 decimal digit(s) are OK.
Best solution is 2.4800450802, with step 0.0000007629, so only first 6 decimal digit(s) are OK.
Indeed, using my calculator I get: 2.480045 + sin2.480045 - 2.480045*sin2.480045 - π/2 --> -3.243x10-7 (i.e. zero, for the uses of our farmer).

This program can be used for any complicated (or not) equation. For example: ln(x/3π) - π = sin(x/1000). The only changes we have to make are, first to replace in the function f, the correct one:
return log(x/(3*pi))-pi-sin(x/1000);
and also, change the values of "a" and "b", to 0.1 and, say, 10000 respectively. The program then yields:
Best solution is 290.3845520020, with step 0.0500000007, so only first 1 decimal digit(s) are OK.
Best solution is 290.4054870605, with step 0.0062500001, so only first 2 decimal digit(s) are OK.
Best solution is 290.4043579102, with step 0.0007812500, so only first 3 decimal digit(s) are OK.
Best solution is 290.4044799805, with step 0.0000976563, so only first 4 decimal digit(s) are OK.

And indeed, we can verify with a calculator that ln(290.4044/(3π)) - π - sin(x/1000) --> -1.0954x10-7.

Log in or register to write something here or to contact authors.