ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 19 Nov 2019 01:27:26 +0100How to find all roots with solve?https://ask.sagemath.org/question/48808/how-to-find-all-roots-with-solve/I have the following quantity:
c_p = 1 - (4*sin(th)^2+2*5*sin(th)/pi+(5/(2*pi))^2)
and I am trying to find its roots (the solutions for `c_p==0`).
When plotting `c_p` as a function of `th` between $-\pi$ and $\pi$, I can see the curve crosses the x-axis at four positions. However, `solve(c_p==0, th)` is only giving two roots:
$$\left[\theta = -\arcsin\left(\frac{5}{4 \ \pi} + \frac{1}{2}\right),\quad \theta = -\arcsin\left(\frac{5}{4 \ \pi} - \frac{1}{2}\right)\right].$$
It appears that `solve` can only find the roots that are in the domain of the $\arcsin$ function, i.e in the interval $[-\dfrac{\pi}{2},\dfrac{\pi}{2}]$. Is there a way to get the other two roots?TofiTue, 19 Nov 2019 01:27:26 +0100https://ask.sagemath.org/question/48808/obtaining all numerical roots of a function in an intervalhttps://ask.sagemath.org/question/8886/obtaining-all-numerical-roots-of-a-function-in-an-interval/Hello, thanks for reading.
I'm working on single variable calculus here:
Basically what I need is what "find_root" does, but I need a list of ALL roots in a given interval, not just one.
So I've been playing with "solve". I found this piece of code which works in most cases:
sage: roots = solve(f(x),x,solution_dict=True)
sage: roots = [s[x] for s in roots]
sage: num_roots = map(n, roots)
but it gives an error if the function is periodic and has inifinite roots, becuase the symbolic expression that "solve" gets has infinite solutions too.
Defining a desired interval should solve this issue, but I have no idea how to implement such thing!
Thanks you and have a good day.NilSun, 15 Apr 2012 01:17:01 +0200https://ask.sagemath.org/question/8886/