2016-07-26 83 views
2

我想在下面的公式計算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

回答

1

感謝@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