我正在尝试在以下等式中解决C
What are the undocumented features and limitations of the Windows FINDSTR command?
我可以使用sympy
为x's
填充x0, x2, ..., x4
,例如i=0
,但似乎无法弄明白如何为t
{{1}执行此操作}}。例如。数量有限
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)
非常感谢任何见解。
答案 0 :(得分: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))
soln_C = solve(s1 - C*s2 - rhs, C)
答案 1 :(得分:0)
我不确定是否可以将其归类为更多的“简洁” ,但是当您知道汇总的上限时,它也可能很有用。假设我们要评估这个表达式:
我们可以用sympy表示并解决它,如下所示:
from sympy import init_session
init_session(use_latex=True)
n = 4
As = symbols('A_1:' + str(n+1))
x = symbols('x')
exp = 0
for i in range(n):
exp += As[i]/(1+x)**(i+1)
Ec = Eq(exp,0)
sol = solve(Ec,x)
#print(sol)
#sol #Or, if you're working on jupyter...