级数求和的辛代数解

2024-05-29 09:50:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在下面的方程中求解C

enter image description here

我可以用sympy来处理一个x's的枚举数,例如x0, x2, ..., x4,但似乎不知道如何对i=0到{}执行此操作。E、 g.数量有限

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)

任何洞察力都将不胜感激。在


Tags: fromalpha数量方程x1x2symbolssympy
2条回答

我不确定这是否可以被归类为更简洁的,但当你知道求和的上限时,它也可能有用。假设我们要计算这个表达式:

我们可以把它表示出来,并用同理式来解决它,如下所示:

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...

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

^{pr2}$

enter image description here

相关问题 更多 >

    热门问题