prove that exists such a
for which if |x-e|<a
method converges
Newton's method works when the approximate solution is near the correct solution.
Newton's method fails when the candidate solution diverges or oscillates.
Add divergence tests (example: a
becomes a not-a-number or infinity) and a loop iteration limit.
Use a binary search to find the upper bound for a
: between a near solution (a = e
) and something that diverges (a = e + 100
). See below.
Repeat (with code adjustments to a_min, a_max
roles and initial values) to find the lower bound for a
. Not shown, left for OP to find. (I found the low side a
to be in the 1.0 to 1.5 range)
int main() {
double x, eps = 1.e-16;
printf("Enter x :\n");
//scanf("%le", &x);
x = e*1.0001;
printf("%le\n", newton(x, eps));
double a_min = e;
double a_max = e + 100.0;
double a;
while (1) {
a = a_min + (a_max - a_min)/2;
if (a == a_min) break;
else if (a == a_max) break;
if (a_min >= a_max) break;
printf("a_min:%20e a_max:%20e a:%20e\n", a_min, a_max, a);
if (isnan(newton(a, eps))) {
a_max = a;
} else {
a_min = a;
}
}
printf("a high side:%e\n", a);
return 0;
}
double newton(double x, double eps) {
double x1;
int i;
for (i=10; i>0; i--) {
//printf("%2d %20e %20e %20e\n", i, x, fd(x), f(x));
if (isnan(x)) return x;
x1 = x - f(x) / fd(x);
if (fabs(x1-x) < eps)
return x1;
x = x1;
}
return 0.0/0.0;
}
Result
Enter x :
2.718282e+00
a_min: 2.718282e+00 a_max: 1.027183e+02 a: 5.271828e+01
a_min: 2.718282e+00 a_max: 5.271828e+01 a: 2.771828e+01
a_min: 2.718282e+00 a_max: 2.771828e+01 a: 1.521828e+01
a_min: 2.718282e+00 a_max: 1.521828e+01 a: 8.968282e+00
a_min: 2.718282e+00 a_max: 8.968282e+00 a: 5.843282e+00
a_min: 2.718282e+00 a_max: 5.843282e+00 a: 4.280782e+00
a_min: 2.718282e+00 a_max: 4.280782e+00 a: 3.499532e+00
a_min: 3.499532e+00 a_max: 4.280782e+00 a: 3.890157e+00
a_min: 3.890157e+00 a_max: 4.280782e+00 a: 4.085469e+00
a_min: 4.085469e+00 a_max: 4.280782e+00 a: 4.183126e+00
a_min: 4.085469e+00 a_max: 4.183126e+00 a: 4.134297e+00
a_min: 4.085469e+00 a_max: 4.134297e+00 a: 4.109883e+00
...
a_min: 4.104323e+00 a_max: 4.104323e+00 a: 4.104323e+00
a high side:4.104323e+00
derive the equation to find this "a" and solve it.
"Derive" --> dang, more fun to simulate as above to find it.
Consider two x
:x_lo
, x_hi
and newton iteration x_better(x) = x - f(x)/f'(x)
.
When next_better(x_lo) == next_better(x_hi)
and x_lo < x_hi
, we are at an oscillation pair.
Rest left for OP. Gotta go.