0

I am very new to programming, and had to use sympy for a school project.

I think I get that using nonlinsolve to return an angle gives an ImageSet with the angle + 2n*pi. However I want it to return only the value of the angle (in the interval [0,pi/2]), and as one value and not an interval.

from sympy import nonlinsolve, symbols,cos
x=symbols('x')
print(nonlinsolve([cos(x)-1],[x]).args[0][0])

I want the result to be 0 and not 2*n*pi.

Clarification : I know that the result is correct, but I only want one value, that I can use algebraically, and I don't know how Sympy works (how to manipulate ImageSets)

Joris
  • 3
  • 3

1 Answers1

0

So I might be wrong because i dont use sympy, but the solution that solvers return seems to be corect to me.

ImageSet(Lambda(_n, 2*_n*pi), Integers)

From what I understand solver returned lambda function. Cosinus is a cyclic function which means it reapeats it's value every 2PI. So the solver says first solution (_n = 0) is 0, second (_n = 1) is 2pi and so on.

look at the function plot and it will hopefully make sense: Wolfram Alpha - (cos(x) - 1)

EDIT: I think you need to use intersect method of imageset like this( note that intersect returns all the intersections, here i selected just the first one):

from sympy import nonlinsolve, symbols,cos, Interval
import math

x = symbols('x')
f = nonlinsolve([cos(x)-1], [x]).args[0][0]
sol = f.intersect(Interval(0, math.pi/2)).args[0]
print(sol)
mlotz
  • 130
  • 3
  • Edit: so if you want the result to be 0 just call that lambda function for 0 argument. – mlotz May 17 '19 at 09:01
  • I might not have been clear. I know that cosinus is cyclic but here I want to know how to convert the "lambda function" to a simple value by restricting the interval of solutions to [0,pi/2]. In this case, I want python to print the number 0. The problem is that I can't find the specific terms to look for to find the related functions. For instance I don't know how to manipulate an ImageSet (as I don't know very much about Sympy) – Joris May 17 '19 at 09:46
  • Edit: I think this is what you are after. – mlotz May 17 '19 at 10:53