0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

「【Ruby】nからmの数の総和を求める」を参考にWolframAlphaとsympy でやってみた。

Last updated at Posted at 2022-02-28

オリジナル

WolframAlpha で


sum_(n=n)^m n = 1/2 (m - n + 1) (m + n)

sum_(n=5)^15 n = 110

結果
110

SymPy Liveで(Pycharmでも)

以下サイトに、ソースコードを貼り付けて、Evaluateです。

from sympy import *
var('k n m')
print("#",Sum(k, (k, n, m))       )
print("#",Sum(k, (k, n, m)).doit())
print("#")
mySubs={n:5,m:15}
print("#",Sum(k, (k, n, m))            .subs(mySubs))
print("#",Sum(k, (k, n, m)).doit()     .subs(mySubs))
print("#",(m**2/2 + m/2 - n**2/2 + n/2).subs(mySubs))
# Sum(k, (k, n, m))
# m**2/2 + m/2 - n**2/2 + n/2
#
# Sum(k, (k, 5, 15))
# 110
# 110

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?