Sympy代数解决一系列求和

Sympy代数解决一系列求和

问题描述:

我想在下面的公式计算CSympy代数解决一系列求和

enter image description here

我可以为enumrated一些x's,如x0, x2, ..., x4sympy做到这一点,但似乎无法弄清楚如何为i=0改为t。例如。数量有限

from sympy import summation, symbols, solve 

x0, x1, x2, x3, x4, alpha, C = symbols('x0, x1, x2, x3, x4, alpha, C') 

e1 = ((x0 + alpha * x1 + alpha**(2) * x2 + alpha**(3) * x3 + alpha**(4) * x4) 
    /(1 + alpha + alpha**(2) + alpha**(3) + alpha**(4))) 
e2 = (x3 + alpha * x4)/(1 + alpha) 
rhs = (x0 + alpha * x1 + alpha**(2) * x2)/(1 + alpha + alpha**(2)) 

soln_C = solve(e1 - C*e2 - rhs, C) 

任何洞察力将不胜感激。

+1

我从来没有使用这个模块个人,但[这](http://docs.sympy.org/latest/modules/concrete.html )建议你可以使用Sum(..)函数(向下滚动到Finite Sums)。 – nbryans

感谢@bryans指示我朝Sum的方向。详细阐述他的评论,这是一个似乎可行的解决方案。由于我对sympy相当陌生,如果任何人有更简洁的方法,请分享。

from sympy import summation, symbols, solve, Function, Sum 

alpha, C, t, i = symbols('alpha, C, t, i') 
x = Function('x') 

s1 = Sum(alpha**i * x(t-i), (i, 0, t))/Sum(alpha**i, (i, 0, t)) 
s2 = Sum(alpha**i * x(t-3-i), (i, 0, t-3))/Sum(alpha**i, (i, 0, t-3)) 
rhs = (x(0) + alpha * x(1) + alpha**(2) * x(2))/(1 + alpha + alpha**(2)) 

enter image description here

soln_C = solve(s1 - C*s2 - rhs, C) 

enter image description here