| 1 | initial version |
A few possible hints:
without Sage: g(x) vanishes if, and only if, x^2 or cos(2*x) vanish, if, and only if, x=0 or there exists k in ZZ such that x = pi/4 + k*pi/2.
now, plot the graph of g around zero:
sage: g.plot()
the root at zero is "double" (aroind zero, g is very similar to x^2), so that a small perturbation (due to numerical noise) of g could either lead to two (roughly opposite) zeros, or no zero at all.
that said, 7.755077210568017e-09 is pretty huge for a numerical noise, how could that be ?
note that 0.1 is not an exact floating-point number, as it can not be written with a finite binary expansion exactly, hence the addition of the step 0.1 with itself could lead to some accumulated shift, see the middle of the output of:
sage: for num in [-10..10,step=.1]:
....: print(num)
[...]
-0.200000000000019
-0.100000000000019
-1.87905246917808e-14
0.0999999999999812
0.199999999999981
0.299999999999981
[...]
compare
sage: find_root(g,-0.100000000000019,-1.87905246917808e-14)
-7.755114791616871e-09
with
sage: find_root(g,-0.1,0)
0.0
| 2 | No.2 Revision |
A few possible hints:
without Sage: g(x) vanishes if, and only if, x^2 or cos(2*x) vanish, if, and only if, x=0 or there exists k in ZZ such that x = pi/4 + k*pi/2.
now, plot the graph of g around zero:
sage: g.plot()
the root at zero is "double" (aroind (around zero, g is very similar to x^2), so that a small perturbation (due to numerical noise) of g could either lead to two (roughly opposite) zeros, or no zero at all.
that said, 7.755077210568017e-09 is pretty huge for a numerical noise, how could that be ?
note that 0.1 is not an exact floating-point number, as it can not be written with a finite binary expansion exactly, hence the addition of the step 0.1 with itself could lead to some accumulated shift, see the middle of the output of:
sage: for num in [-10..10,step=.1]:
....: print(num)
[...]
-0.200000000000019
-0.100000000000019
-1.87905246917808e-14
0.0999999999999812
0.199999999999981
0.299999999999981
[...]
compare
sage: find_root(g,-0.100000000000019,-1.87905246917808e-14)
-7.755114791616871e-09
with
sage: find_root(g,-0.1,0)
0.0
Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.