我在sage终端输入以下内容
k = var('k')
总和(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:
有人可以解决我的问题吗?
答案 0 :(得分:0)
您声明了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