Ask Your Question

Revision history [back]

Hi,

find_root gives only one root in the given interval because it implements a secant-based method that is called Brent's algorithm. It is provided by SciPy's scipy.optimize.brentq.

If you want to find the zeros numerically, my first attempt would be to partition the given interval into smaller subintervals; the precondition for several of these root-finding algorithms (as explained in the docs) is that the function changes sign in the given interval.

If you want to find the roots symbolically, Sage provides the solve method, you can access the documentation by typing solve? and the ENTER key. In your example,

sage: solve(sin(x) == cos(pi/2 + x), x)
[x == 0]

In this case, it gives only the root at x=0, although other cases (eg. try with polynomials), it can give all roots. But Sage allows to call different software interfaces. We can try SymPy's solveset:

sage: from sympy import solveset, symbols, sin, cos, pi
sage: x = symbols('x')
sage: solveset(sin(x) - cos(pi/2 + x), x)
ImageSet(Lambda(_n, 2*_n*pi), Integers()) U ImageSet(Lambda(_n, 2*_n*pi + pi), Integers())

The nuisance with SymPy is that you have to make many imports by hand. Anyway, in this case, it does produces all the roots, one interprets as:

$$ S = \left{ 2 n \pi : n \in \mathbb{Z}\right} \cup \left{ 2 n \pi + \pi : n \in \mathbb{Z}\right}. $$

Hi,

find_root gives only one root in the given interval because it implements a secant-based method that is called Brent's algorithm. It is provided by SciPy's scipy.optimize.brentq.

If you want to find the zeros numerically, my first attempt would be to partition the given interval into smaller subintervals; the precondition for several of these root-finding algorithms (as explained in the docs) is that the function changes sign in the given interval.

If you want to find the roots symbolically, Sage provides the solve method, you can access the documentation by typing solve? and the ENTER key. In your example,

sage: solve(sin(x) == cos(pi/2 + x), x)
[x == 0]

In this case, it gives only the root at x=0, although other cases (eg. try with polynomials), it can give all roots. But Sage allows to call different software interfaces. We can try SymPy's solveset:

sage: from sympy import solveset, symbols, sin, cos, pi
sage: x = symbols('x')
sage: solveset(sin(x) - cos(pi/2 + x), x)
ImageSet(Lambda(_n, 2*_n*pi), Integers()) U ImageSet(Lambda(_n, 2*_n*pi + pi), Integers())

The nuisance with SymPy is that you have to make many imports by hand. Anyway, in this case, it does produces all the roots, that one interprets as:

$$ S = \left{ { 2 n \pi : n \in \mathbb{Z}\right} \mathbb{Z}} \cup \left{ { 2 n \pi + \pi : n \in \mathbb{Z}\right}. $$

\mathbb{Z}}. $$

Hi,

find_root gives only one root in the given interval because it implements a secant-based method that is called Brent's algorithm. It is provided by SciPy's scipy.optimize.brentq.

If you want to find the zeros numerically, my first attempt would be to partition the given interval into smaller subintervals; the precondition for several of these root-finding algorithms (as explained in the docs) is that the function changes sign in the given interval.

If you want to find the roots symbolically, Sage provides the solve method, you can access the documentation by typing solve? and the ENTER key. In your example,

sage: solve(sin(x) == cos(pi/2 + x), x)
[x == 0]

In this case, it gives only the root at x=0, although other cases (eg. try with polynomials), it can give all roots. But Sage allows to call different software interfaces. We can try SymPy's solveset:

sage: from sympy import solveset, symbols, sin, cos, pi
sage: x = symbols('x')
sage: solveset(sin(x) - cos(pi/2 + x), x)
ImageSet(Lambda(_n, 2*_n*pi), Integers()) U ImageSet(Lambda(_n, 2*_n*pi + pi), Integers())

The nuisance with SymPy is that you have to make many imports by hand. Anyway, in this case, it does produces all the roots, that one interprets as:

$$ S = { \{ 2 n \pi : n \in \mathbb{Z}} \mathbb{Z}\} \cup { \{ 2 n \pi + \pi : n \in \mathbb{Z}}. \mathbb{Z}\}. $$

Hi,

find_root gives only one root in the given interval because it implements a secant-based method that is called Brent's algorithm. It is provided by SciPy's scipy.optimize.brentq.

If you want to find the zeros numerically, my first attempt would be to partition the given interval into smaller subintervals; the precondition for several of these root-finding algorithms (as explained in the docs) is that the function changes sign in the given interval.

If you want to find the roots symbolically, Sage provides the solve method, you can access the documentation by typing solve? and the ENTER key. In your example,

sage: solve(sin(x) == cos(pi/2 + x), x)
[x == 0]

In this case, it gives only the root at x=0, although other cases (eg. try with polynomials), it can give all roots. But Sage allows to call interface many different software interfaces. mathematical software. We can try SymPy's solveset:

sage: from sympy import solveset, symbols, sin, cos, pi
sage: x = symbols('x')
sage: solveset(sin(x) - cos(pi/2 + x), x)
ImageSet(Lambda(_n, 2*_n*pi), Integers()) U ImageSet(Lambda(_n, 2*_n*pi + pi), Integers())

The nuisance with SymPy is that you have to make many imports by hand. Anyway, in this case, it does produces all the roots, that one interprets as:

$$ S = \{ 2 n \pi : n \in \mathbb{Z}\} \cup \{ 2 n \pi + \pi : n \in \mathbb{Z}\}. $$

Hi,

find_root gives only one root in the given interval because it implements a secant-based method that is called Brent's algorithm. It is provided by SciPy's scipy.optimize.brentq.

If you want to find the zeros numerically, my first attempt would be to partition the given interval into smaller subintervals; the precondition for several of these root-finding algorithms (as explained in the docs) is that the function changes sign in the given interval.

If you want to find the roots symbolically, Sage provides the solve method, you can access the documentation by typing solve? and the ENTER key. In your example,

sage: solve(sin(x) == cos(pi/2 + x), x)
[x == 0]

In this case, it case solve, which refers to Maxima's solve algorithm, gives only the root at x=0, although other cases (eg. try with polynomials), it can give all roots. But Sage allows to interface many different mathematical software. We can try SymPy's solveset:

sage: from sympy import solveset, symbols, sin, cos, pi
sage: x = symbols('x')
sage: solveset(sin(x) - cos(pi/2 + x), x)
ImageSet(Lambda(_n, 2*_n*pi), Integers()) U ImageSet(Lambda(_n, 2*_n*pi + pi), Integers())

The nuisance with SymPy is that you have to make many imports by hand. Anyway, in this case, it does produces all the roots, that one interprets as:

$$ S = \{ 2 n \pi : n \in \mathbb{Z}\} \cup \{ 2 n \pi + \pi : n \in \mathbb{Z}\}. $$

Hi,

find_root gives only one root in the given interval because it implements a secant-based method that is called Brent's algorithm. It is provided by SciPy's scipy.optimize.brentq.

If you want to find the zeros numerically, my first attempt would be to partition the given interval into smaller subintervals; the precondition for several of these root-finding algorithms (as explained in the docs) is that the function changes sign in the given interval.

If you want to find the roots symbolically, Sage provides the solve method, you can access the documentation by typing solve? and the ENTER key. In your example,

sage: solve(sin(x) == cos(pi/2 + x), x)
[x == 0]

In this case solve, which refers to Maxima's solve algorithm, gives only the root at x=0, although other cases (eg. try with polynomials), it can give all roots. But Sage allows to interface many different mathematical software. We can try SymPy's solveset:

sage: from sympy import solveset, symbols, sin, cos, pi
sage: x = symbols('x')
sage: solveset(sin(x) - cos(pi/2 + x), x)
ImageSet(Lambda(_n, 2*_n*pi), Integers()) U ImageSet(Lambda(_n, 2*_n*pi + pi), Integers())

The nuisance with SymPy this approach is that you have to make many imports by hand. Anyway, in this case, it does produces all the roots, that one interprets as:

$$ S = \{ 2 n \pi : n \in \mathbb{Z}\} \cup \{ 2 n \pi + \pi : n \in \mathbb{Z}\}. $$

Hi,

find_root gives only one root in the given interval because it implements a secant-based method that is called Brent's algorithm. It is provided by SciPy's scipy.optimize.brentq.

If you want to find the zeros numerically, my first attempt would be to partition the given interval into smaller subintervals; the precondition for several of these root-finding algorithms (as explained in the docs) is that the function changes sign in the given interval.

If you want to find the roots symbolically, Sage provides the solve method, you can access the documentation by typing solve? and the ENTER key. In your example,

sage: solve(sin(x) == cos(pi/2 + x), x)
[x == 0]

In this case solve, which refers to Maxima's solve algorithm, gives only the root at x=0, although other cases (eg. try with polynomials), it can give all roots. But Sage allows to interface many different mathematical software. We can try SymPy's solveset:

sage: from sympy import solveset, symbols, sin, cos, pi
sage: x = symbols('x')
sage: solveset(sin(x) - cos(pi/2 + x), x)
ImageSet(Lambda(_n, 2*_n*pi), Integers()) U ImageSet(Lambda(_n, 2*_n*pi + pi), Integers())

The nuisance with this approach is that you have to make many imports by hand. hand (*). Anyway, in this case, it does produces all the roots, that one interprets as:

$$ S = \{ 2 n \pi : n \in \mathbb{Z}\} \cup \{ 2 n \pi + \pi : n \in \mathbb{Z}\}. $$

(*) A trick is to use the function sympy.sympify, as in sympify(sin(x) - cos(pi/2 + x)).

Hi,

find_root gives only one root in the given interval because it implements a secant-based method that is called Brent's algorithm. It is provided by SciPy's scipy.optimize.brentq.

If you want to find the zeros numerically, my first attempt would be to partition the given interval into smaller subintervals; the precondition for several of these root-finding algorithms (as explained in the docs) is that the function changes sign in the given interval.

If you want to find the roots symbolically, Sage provides the solve method, you can access the documentation by typing solve? and the ENTER key. In your example,

sage: solve(sin(x) == cos(pi/2 + x), x)
[x == 0]

In this case solve, which refers to Maxima's solve algorithm, gives only the root at x=0, although other cases (eg. try with polynomials), it can give all roots. But Sage allows to interface many different mathematical software. We can try SymPy's solveset:

sage: from sympy import solveset, symbols, sin, cos, pi
sage: x = symbols('x')
sage: solveset(sin(x) - cos(pi/2 + x), x)
ImageSet(Lambda(_n, 2*_n*pi), Integers()) U ImageSet(Lambda(_n, 2*_n*pi + pi), Integers())

The nuisance with this approach is that you have to make many imports by hand (*). Anyway, in In this case, it does produces all the roots, that one interprets as:

$$ S = \{ 2 n \pi : n \in \mathbb{Z}\} \cup \{ 2 n \pi + \pi : n \in \mathbb{Z}\}. $$

(*) A trick is The nuisance with this approach is that you have to make many imports by hand.. it is sometimes helpful to use the function sympy.sympify, as in sympify(sin(x) - cos(pi/2 + x)).

, which does the imports automatically.

Hi,

find_root gives only one root in the given interval because it implements a secant-based method that is called Brent's algorithm. It is provided by SciPy's scipy.optimize.brentq.

If you want to find the zeros numerically, my first attempt would be to partition the given interval into smaller subintervals; the precondition for several of these root-finding algorithms (as explained in the docs) is that the function changes sign in the given interval.

If you want to find the roots symbolically, Sage provides the solve method, you can access the documentation by typing solve? and the ENTER key. In your example,

sage: solve(sin(x) == cos(pi/2 + x), x)
[x == 0]

In this case solve, which refers to Maxima's solve algorithm, gives only the root at x=0, although other cases (eg. try with polynomials), it can give all roots. But Sage allows to interface many different mathematical software. We can try SymPy's solveset:

sage: from sympy import solveset, symbols, sin, cos, pi
sage: x = symbols('x')
sage: solveset(sin(x) - cos(pi/2 + x), x)
ImageSet(Lambda(_n, 2*_n*pi), Integers()) U ImageSet(Lambda(_n, 2*_n*pi + pi), Integers())

In this case, it does produces case we obtain all the roots, that one interprets as:

$$ S = \{ 2 n \pi : n \in \mathbb{Z}\} \cup \{ 2 n \pi + \pi : n \in \mathbb{Z}\}. $$

The nuisance with this approach is that you have to make many imports by hand.. it is sometimes helpful to use the function sympy.sympify, as in sympify(sin(x) - cos(pi/2 + x)), which does the imports automatically.

Hi,

find_root gives only one root in the given interval because it implements a secant-based method that is called Brent's algorithm. It is provided by SciPy's scipy.optimize.brentq.

If you want to find the zeros numerically, my first attempt would be to partition the given interval into smaller subintervals; the precondition for several of these root-finding algorithms (as explained in the docs) is that the function changes sign in the given interval.

If you want to find the roots symbolically, Sage provides the solve method, you can access the documentation by typing solve? and the ENTER key. In your example,

sage: solve(sin(x) == cos(pi/2 + x), x)
[x == 0]

In this case solve, which refers to Maxima's solve algorithm, gives only the root at x=0, although other cases (eg. try with polynomials), it can give all roots. But Sage allows to interface many different mathematical software. We can try SymPy's solveset:

sage: from sympy import solveset, symbols, sin, cos, pi
sage: x = symbols('x')
sage: solveset(sin(x) - cos(pi/2 + x), x)
ImageSet(Lambda(_n, 2*_n*pi), Integers()) U ImageSet(Lambda(_n, 2*_n*pi + pi), Integers())

In One interprets this case we obtain all the roots, that one interprets answer as:

$$ S = \{ 2 n \pi : n \in \mathbb{Z}\} \cup \{ 2 n \pi + \pi : n \in \mathbb{Z}\}. $$

The nuisance with this approach is that you have to make many imports by hand.. it is sometimes helpful to use the function sympy.sympify, as in sympify(sin(x) - cos(pi/2 + x)), which does the imports automatically.