Processing math: 100%
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

answered 6 years ago

Juanjo gravatar image

Root finding is a difficult subject. In general, you cannot expect an algorithm to yield all the solutions of a given equation f(x)=0. It is required some prior knowledge and analysis of the equation.

The solve function tries to obtain exact solutions, if any. For the equation you propose, that is, sinx=0.8, you have already tested

solve(sin(x)==0.8,x)

which yields x=arcsin(4/5) and misses the other solution in [0,2π], which is x=πarcsin(4/5). You have also tried

solve(sin(x)==0.8, x, to_poly_solve = 'force')

and got something like

[x == pi + 2*pi*z103 - arctan(3602879701896397/7301667457314599911469129704407*sqrt(7301667457314599911469129704407)),
 x == 2*pi*z105 + arctan(3602879701896397/7301667457314599911469129704407*sqrt(7301667457314599911469129704407))]

Here, z103 and z105 represent integer constants. Every time you evaluate such a function, you get different numbers after z. In a more mathematical notation, Sage proposes the solutions x=arctan(abb)+π(2z103+1)andx=arctan(abb)+2πz105, where a=3602879701896397andb=7301667457314599911469129704407. Please, note that we have now an infinite number of solutions. If z103 and z105 are replaced by given integers, we get specific solutions. For example,

sol = solve(sin(x)==0.8, x, to_poly_solve = 'force')
print "First solution:", sol[0].rhs().subs(z103=0).n()
print "Second solution:",sol[1].rhs().subs(z105=0).n()

yields

First solution: 2.21429743558818
Second solution: 0.927295218001612

assuming, of course, that z103 and z105 still were the constants appearing in sol. These are the expected roots (up to an error of order 1016) in [0,2π], since

sage: print N(arcsin(4/5)), N(pi-arcsin(4/5))
0.927295218001612 2.21429743558818

The find_root function applies a numerical algorithm, essentially Brent's method. So each call to find_root will yield, if any, just one approximated root of the equation. Hence, to find all the zeros of a function, you need to know in advance how many they are and where they live and then use find_root as many times as needed, changing the corresponding intervals.