How would I solve an equation containing a summation expression, i.e. something like.
I would consider the following code fragment to solve this equation:
from sympy import *
i, N, x = symbols("n, N, x")
y = Function("y")
eq = summation(x + y(i), (i, 0, N))
print solve(eq, [x])
However, while this equation is simple solve()
does not produce a result. The
expected solution would be
I believe the plain answer is that it's just too complicated for the currecnt system to make the substitutions required.
With that said, there might be an issue with expansion of summation here.
I managed to get the correct answer by changing the Sum
s in the expand
output with summation
s, see console session below.
The reason which I believe made the last one possible, is that summation(x, (i, 0, N))
evaluates to x*(N + 1)
(effect of the summation
function), while the Sum(x, (i, 0, N))
returned by the expansion remains a simple Sum
object, therefore no substitution made for it after the inner expansion in the solve
function.
>>> from sympy import *
>>>
>>> i, N, x, y = symbols("i, N, x, y")
>>> eq = summation(x + y(i), (i, 0, N))
>>>
>>> expand(eq)
Sum(x, (i, 0, N)) + Sum(y(i), (i, 0, N))
>>>
>>> solve(summation(x, (i, 0, N)) + summation(y(i), (i, 0, N)), x)
[Sum(-y(i), (i, 0, N))/(N + 1)]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With