简体   繁体   English

在 SymPy 中计算总和

[英]Evaluating a sum in SymPy

I want to evaluate the sum我要评估总和

using Python and SymPy, I'm relatively new using SymPy and the first thing I tried was使用 Python 和 SymPy,我是使用 SymPy 的新手,我尝试的第一件事是

from sympy import exp, oo, summation, symbols

n, x = symbols('n,x')
summation(exp(-n*x), (n, 1, oo))

But it doesn't work, it just returns the unevaluated sum.但它不起作用,它只是返回未计算的总和。 I can make it work using我可以使用它来工作

from sympy import exp, oo, summation, symbols

n, x = symbols('n,x')
f = exp(-x)
summation(x**(-n), (n, 1, oo)).subs(x,f)

But I would like to know if it is possible to make it work without need to break the expression into x^n and then substitute x by e^-x.但我想知道是否有可能在不需要将表达式分解为 x^n 然后用 e^-x 替换 x 的情况下使其工作。

Thank you谢谢

Try using the following:尝试使用以下内容:

x , n = smp.symbols('x n')
smp.Sum(smp.exp(-n*x),(n, 1, smp.oo))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM