Another approach for these problems is to use, as a starting point, solutions to a simpler problem which become initial guess to the more difficult problem. e.g. solving sin(x)=0.2 will give you two solutions and as many others as you want by adding or subtraction 2pi. Then these approximate solutions can be used as initial guesses for nsolve as you change the problem to `sin(x)-(a*x+0.2)` with `a` increasing as quickly as possible from 0 to 0.5 (in your case). This is the "continuation" method.
/c On Saturday, December 21, 2019 at 2:17:52 AM UTC-6, Philipp Gressly Freimann wrote: > > Hello > > Well, thanks a lot. Works great. I did not know the "nsolve" command. > > If I am right, there is no command to find all three solutions? > > φ > > Am Freitag, 20. Dezember 2019 11:48:03 UTC+1 schrieb Oscar: >> >> You can use nsolve to find numerical solutions: >> ``` >> In [10]: nsolve(Eq(sin(x), 0.5*x + 0.2), x, 0) >> Out[10]: 0.425436108484597 >> ``` >> This will find one root at a time starting from an initial guess (I've >> used zero). >> >> Initial guesses -1 and +1 give two other roots. >> ``` >> In [11]: nsolve(Eq(sin(x), 0.5*x + 0.2), x, -1) >> Out[11]: -2.11307244875263 >> >> In [12]: nsolve(Eq(sin(x), 0.5*x + 0.2), x, +1) >> Out[12]: 1.59919364642736 >> ``` >> >> You can get more precise solutions using prec: >> ``` >> In [15]: nsolve(Eq(sin(x), 0.5*x + 0.2), x, 0, prec=50) >> Out[15]: 0.42543610848459725447179186114511470949330179080539 >> ``` >> >> -- >> Oscar >> >> On Fri, 20 Dec 2019 at 10:26, Philipp Gressly Freimann >> <[email protected]> wrote: >> > >> > Hello >> > >> > I want to solve the following equation numerically between -PI and PI: >> > >> > sin(x) = 0.5x + 0.2 >> > >> > [which is similar to sin(x) - 0.5x - 0.2 = 0] >> > >> > The graph shows me three solutions. Is there a possibility to solve >> this equation numerically using sympy? >> > >> > Thanks in advance >> > >> > φ >> > >> > -- >> > You received this message because you are subscribed to the Google >> Groups "sympy" group. >> > To unsubscribe from this group and stop receiving emails from it, send >> an email to [email protected]. >> > To view this discussion on the web visit >> https://groups.google.com/d/msgid/sympy/abc402b1-ac1a-4508-95a8-c13a48483654%40googlegroups.com. >> >> >> > -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/3628d900-e93d-48cd-bdfc-e35b5db883c5%40googlegroups.com.
