How to do a Sigma in python 3

A sigma (∑) is a Summation operator. It evaluates a certain expression many times, with slightly different variables, and returns the sum of all those expressions.

For example, in the Ballistic coefficient formula

The Python implementation would look something like this:

# Just guessing some values. You have to search the actual values in the wiki.
ballistic_coefficients = [0.3, 0.5, 0.1, 0.9, 0.1]

total_numerator = 0
total_denominator = 0
for i, coefficient in enumerate(ballistic_coefficients):
    total_numerator += 2**(-i) * coefficient
    total_denominator += 2**(-i)
print('Total:', total_numerator / total_denominator)

You may want to look at the enumerate function, and beware precision problems.

Leave a Comment