2

I am trying to find all roots in a range, using

y /. FindRoot[Sin[y] == 0, {y, #}] & /@ Range[7]

which gives

{0., 3.14159, 3.14159, 3.14159, 9.42478, 6.28319, 6.28319}

but I would like to get

{0., 3.14159, 6.28319}

What am I doing wrong?

martin
  • 8,678
  • 4
  • 23
  • 70
  • 1
    Reduce can often find all roots in an interval. Have you tried it? http://blog.wolfram.com/2008/12/18/mathematica-7-johannes-kepler-and-transcendental-roots/ – Szabolcs Apr 20 '14 at 23:56
  • 2
    If for some reasons you want to work with FindRoot (e.g. because it is much faster for a large class of transcendental equations) you may exploit the technique using RootIntervals as in this answer First positive root and instead of Sin[x] use the first terms of its Taylor series e.g. N@First@RootIntervals[Series[Sin[x], {x, 0, 15}] // Normal]. This information is all you may need to work out the solution. – Artes Apr 21 '14 at 00:02
  • @Szabolcs - many thanks - solved with Reduce as you suggested :) – martin Apr 21 '14 at 02:56
  • @Artes - many thanks - great links - ended up using Reduce - by looking at your answer here :) – martin Apr 21 '14 at 02:57
  • @martin I'm glad it worked. It doesn't always work and it's much slower than FindRoot-based solutions. – Szabolcs Apr 21 '14 at 03:47
  • 1
    @martin I think you can answer your question using FindRoot as well even though I wouldn't use it here (Solve[Sin[x] == 0 && 0 <= x <= 2 Pi, x] works too ). For transcendental equations involving trigonometric functions as algebraic variables Reduce and Solve will work in general (look e.g. here How to get intersection values from a parametric graph? for a simple exception of Solve). – Artes Apr 21 '14 at 09:01
  • 2
    You could also use NSolve[Sin[x] == 0 && 0 <= x <= 7, x] which gives the result {{x -> 0.}, {x -> 3.14159}, {x -> 6.28319}}. – Stephen Luttrell Apr 21 '14 at 11:01
  • You could also use y /. FindRoot[Sin[y] == 0, {y, #}] & /@ Range[7] // Union – chris Apr 21 '14 at 13:15

0 Answers0