2
$\begingroup$

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?

$\endgroup$
  • 1
    $\begingroup$ Reduce can often find all roots in an interval. Have you tried it? blog.wolfram.com/2008/12/18/… $\endgroup$ – Szabolcs Apr 20 '14 at 23:56
  • 2
    $\begingroup$ 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. $\endgroup$ – Artes Apr 21 '14 at 0:02
  • $\begingroup$ @Szabolcs - many thanks - solved with Reduce as you suggested :) $\endgroup$ – martin Apr 21 '14 at 2:56
  • 1
    $\begingroup$ @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). $\endgroup$ – Artes Apr 21 '14 at 9:01
  • 2
    $\begingroup$ You could also use NSolve[Sin[x] == 0 && 0 <= x <= 7, x] which gives the result {{x -> 0.}, {x -> 3.14159}, {x -> 6.28319}}. $\endgroup$ – Stephen Luttrell Apr 21 '14 at 11:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.