【问题标题】:Can't not compute sum in Sage - Setup error?无法在 Sage 中计算总和 - 设置错误?
【发布时间】:2013-12-24 17:08:16
【问题描述】:

我在 sage 终端中输入以下内容

k = var('k')

sum(k^2, k, 1, n)

输出应该是:

1/3*n^3 + 1/2*n^2 + 1/6*n

输出实际上是:

TypeError                                 Traceback (most recent call last)
<ipython-input-8-4790b7807cd9> in <module>()
----> 1 sum(k**Integer(2), k, Integer(1), n)

/Applications/Sage-5.12-OSX-64bit-10.8.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/misc/functional.pyc in symbolic_sum(expression, *args, **kwds)
    652     """
    653     if hasattr(expression, 'sum'):
--> 654         return expression.sum(*args, **kwds)
    655     elif len(args) <= 1:
    656         return sum(expression, *args)

/Applications/Sage-5.12-OSX-64bit-10.8.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/symbolic/expression.so in sage.symbolic.expression.Expression.sum (sage/symbolic/expression.cpp:40331)()

/Applications/Sage-5.12-OSX-64bit-10.8.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/calculus/calculus.pyc in symbolic_sum(expression, v, a, b, algorithm)
    578             raise TypeError("need a summation variable")
    579 
--> 580     if v in SR(a).variables() or v in SR(b).variables():
    581         raise ValueError("summation limits must not depend on the summation variable")
    582 

/Applications/Sage-5.12-OSX-64bit-10.8.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/structure/parent.so in sage.structure.parent.Parent.__call__ (sage/structure/parent.c:8372)()

/Applications/Sage-5.12-OSX-64bit-10.8.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/structure/coerce_maps.so in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (sage/structure/coerce_maps.c:3856)()

/Applications/Sage-5.12-OSX-64bit-10.8.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/structure/coerce_maps.so in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (sage/structure/coerce_maps.c:3757)()

/Applications/Sage-5.12-OSX-64bit-10.8.app/Contents/Resources/sage/local/lib/python2.7/site-packages/sage/symbolic/ring.so in sage.symbolic.ring.SymbolicRing._element_constructor_ (sage/symbolic/ring.cpp:4958)()

TypeError:

有人可以帮我解决问题吗?

【问题讨论】:

    标签: macos ipython sage


    【解决方案1】:

    你声明了k,但没有声明n,所以你得到了默认的n,它是一个函数:

    sage: n
    <function sage.misc.functional.numerical_approx>
    

    做和k一样的事情:

    sage: k, n = var("k n")
    sage: sum(k^2, k, 1, n)
    1/3*n^3 + 1/2*n^2 + 1/6*n
    

    【讨论】:

      猜你喜欢
      • 2019-03-22
      • 2018-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多