-Background -[What is Σ](http://qiita.com/weedslayer/items/25c38c928ad59ba61071#What is Σ) -[What you want to do](http://qiita.com/weedslayer/items/25c38c928ad59ba61071 #What you want to do) -[Check operation with Python](http://qiita.com/weedslayer/items/25c38c928ad59ba61071#Check operation with Python) -[Lighten the example](http://qiita.com/weedslayer/items/25c38c928ad59ba61071 #Lighten the example) -[Extra edition ~ what if ~](http://qiita.com/weedslayer/items/25c38c928ad59ba61071 # Extra edition ~ what if ~)
In a word, it is expressed as sum or (mainly) the sum of a sequence.

See below for detailed usage:
What was the meaning of Σ? [Sequence 9] Sigma 1 What is Sigma? Explain the meaning and calculation of Sigma [High 2 Mathematics / Number B] Sum of sequences ~ Definition and calculation method of sigma Σ: Visual mathematics (math B: sequence
Refer to the source,

I managed to get it to work with python.
Below is the original code
sigma.py
def f(x):
    return 2*x + 1
def g(x):
    return (x-1) * (x-3)
def sigma(func, frm, to:
    result = 0;
    for i in range(frm, to+1):
        result += func(i)
    return result
sigma(f, 2, 4) #21
sigma(g, 1, 3) #-1
See here for the detailed flow.
Make this work with Python 3.x
sigma2.py
def f(x):
	return 
def sigma(func, frm, to):
	result = 0;
	for i in range(frm, to+1):
		result += func(i)
	print(result)
sigma(f, 1, 10) #21
Example: Find the sum of the following equations.

this
 --- #1
When
 --- #2 (これが上の画像で言うk番目のa)
Divide into.
First, create a function that gives the answer of # 2.
def f(n):
    return 3 * n - 2
And the function that gives the answer of # 1
def sigma(func, frm, to):
	result = 0; #Answer saucer
	for i in range(frm, to+1):
		result += func(i) 
		#Call the function here. By the way, here i= x
	print(result)
The completed form looks like this
ef f(n):
	return 3 * n - 2  
def sigma(func, frm, to):
	result = 0; #Answer saucer
	for i in range(frm, to+1):
		result += func(i) 
		#Call the function here. By the way, here i= x
	print(result)
sigma(f, 1, 4) #22
If you come across an expression that doesn't require you to create an expression for f (x)
func of the sigma functionresult + = func (i) to result + = idef sigma2(frm, to):
	result = 0;
	for i in range(frm, to+1):
		result += i
	print(result)
sigma2(1,10) #55
        Recommended Posts