I did this little python test program to see how solve and nsolve .
from sympy import * theta = Symbol('theta') phi = Symbol('phi') def F(theta,phi): return sin(theta)*cos(phi)+cos(phi)**2 def G(phi): return ((1 + sqrt(3))*sin(phi) - 4*pi*sin(2*phi)*cos(2*phi)) solution1 = solve(F(pi/2,phi),phi) solution2 = solve(G(phi),phi) solution3 = nsolve(G(phi),0) solution4 = nsolve(G(phi),1) solution5 = nsolve(G(phi),2) solution6 = nsolve(G(phi),3) print solution1, solution2, solution3, solution4, solution5, solution6
And I get this output:
[pi/2, pi] [] 0.0 -0.713274788952698 2.27148961717279 3.14159265358979
The first call to the solution gave me two solutions to the corresponding function. But not the second. I wonder why? nsolve seems to work with the initial test value, but depending on this value it gives different numerical solutions. Is there a way to get a list of all numerical solutions using nsolve or with another function in only one line?
source share