-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sympy can't solve this double angular summation #23576
Comments
The code you've shown doesn't match the depicted formula so I'm not sure exactly what sum you want to compute. I'm not sure what approach could be used for sums like this in general. The only thing I can think is rewriting to exp. If you declare v as a positive integer then rewrite as In [16]: v = symbols('v', integer=True, positive=True)
In [17]: i, j = symbols('i, j')
In [18]: s = 2*Sum(1 - cos(2*pi*(i - j)/v), (i, 1, v), (j, 1, v))
In [19]: s
Out[19]:
v v
____ ____
╲ ╲
╲ ╲
╲ ╲ ⎛ ⎛2⋅π⋅(i - j)⎞⎞
2⋅ ╱ ╱ ⎜1 - cos⎜───────────⎟⎟
╱ ╱ ⎝ ⎝ v ⎠⎠
╱ ╱
‾‾‾‾ ‾‾‾‾
j = 1 i = 1
In [20]: s.doit()
Out[20]:
v v
____ ____
╲ ╲
╲ ╲
╲ ╲ ⎛ ⎛2⋅π⋅(i - j)⎞⎞
2⋅ ╱ ╱ ⎜1 - cos⎜───────────⎟⎟
╱ ╱ ⎝ ⎝ v ⎠⎠
╱ ╱
‾‾‾‾ ‾‾‾‾
j = 1 i = 1
In [21]: s.rewrite(exp)
Out[21]:
v v
_____ _____
╲ ╲
╲ ╲ ⎛ 2⋅ⅈ⋅π⋅(i - j) -2⋅ⅈ⋅π⋅(i - j) ⎞
╲ ╲ ⎜ ───────────── ───────────────⎟
╲ ╲ ⎜ v v ⎟
2⋅ ╱ ╱ ⎜ ℯ ℯ ⎟
╱ ╱ ⎜- ────────────── + 1 - ────────────────⎟
╱ ╱ ⎝ 2 2 ⎠
╱ ╱
‾‾‾‾‾ ‾‾‾‾‾
j = 1 i = 1
In [22]: s.rewrite(exp).doit()
Out[22]:
⎛⎧ 2⋅ⅈ⋅π ⎞ ⎛⎧
⎜⎪ ───── ⎟ ⎜⎪
⎜⎪ v ⎟ ⎜⎪
⎜⎪ v for ℯ = 1⎟ ⎜⎪ v
⎛⎧ -2⋅ⅈ⋅π ⎞ ⎜⎪ ⎟ ⎜⎪
⎜⎪ ─────── ⎟ ⎜⎪ 2⋅ⅈ⋅π 2⋅ⅈ⋅π⋅(v + 1) ⎟ ⎜⎪ -2⋅ⅈ⋅π⋅(v + 1)
2 ⎜⎪ v ⎟ ⎜⎪ ───── ───────────── ⎟ ⎜⎪ ───────────────
2⋅v - ⎜⎨v for ℯ = 1⎟⋅⎜⎨ v v ⎟ - ⎜⎨ v
⎜⎪ ⎟ ⎜⎪ℯ - ℯ ⎟ ⎜⎪- ℯ + ℯ
⎜⎪0 otherwise ⎟ ⎜⎪─────────────────────── otherwise ⎟ ⎜⎪──────────────────────
⎝⎩ ⎠ ⎜⎪ 2⋅ⅈ⋅π ⎟ ⎜⎪ -2⋅ⅈ⋅π
⎜⎪ ───── ⎟ ⎜⎪ ───────
⎜⎪ v ⎟ ⎜⎪ v
⎜⎪ 1 - ℯ ⎟ ⎜⎪ 1 - ℯ
⎝⎩ ⎠ ⎝⎩
-2⋅ⅈ⋅π ⎞
─────── ⎟
v ⎟
for ℯ = 1⎟
⎟ ⎛⎧ 2⋅ⅈ⋅π ⎞
-2⋅ⅈ⋅π ⎟ ⎜⎪ ───── ⎟
─────── ⎟ ⎜⎪ v ⎟
v ⎟⋅⎜⎨v for ℯ = 1⎟
⎟ ⎜⎪ ⎟
─────── otherwise ⎟ ⎜⎪0 otherwise ⎟
⎟ ⎝⎩ ⎠
⎟
⎟
⎟
⎠
In [23]: simplify(_)
Out[23]:
⎧ -2⋅ⅈ⋅π 2⋅ⅈ⋅π
⎪ ─────── ─────
⎪ v v
⎨ 0 for ℯ = 1 ∧ ℯ = 1
⎪
⎪ 2
⎩2⋅v otherwise I think that the problem is that we need |
I should've specified that the assumptions are that v is a positive integer, but in practise it's larger than 2 and probably 3; and that v is the the number of vertices of a 2D polygon. Rewrite exp looks like the way though I don't understand how mathematica and wolfram know to try that, unless they just have more summation identities? |
Hi all,
In wolfram alpha it comes out correctly as
=v
sqrt(sum_i=1^v (sum_j=1^v 2*((((1)*(1))-((1)*(1))cos(2*pi/v*((j-1)-(i-1)))))))
In sympy it outright gives up.
sp.sympify('2*Sum(1 - cos(2*pi*(i - j)/v), (i, 1, v))').doit()
Any thoughts?
Thanks
Craig
The text was updated successfully, but these errors were encountered: