Escolar Documentos
Profissional Documentos
Cultura Documentos
Introduction
When computer science students learn the concepts of control structures, particularly repetition structures, they often come
across exercises involving converging series.
Thinking about this difficulty, I have separated classical algorithms involving some of these series.
Background
A series is convergent if the sequence of its partial sums tends to a limit (L). That means that the partial sums become closer and
closer to a given number when the number of their terms increases. If the series is convergent, the number L (necessarily unique)
is called the sum of the series. (WikiPedia)
https://www.codeproject.com/Tips/1264872/Algorithms-for-Calculating-Convergent-Series?display=Print 1/4
05/11/2018 Algorithms for Calculating Convergent Series - CodeProject
import math
# 1.0 Calculating Euler's constant by the Taylor series (More readable version)
print('e = ',v)
print()
print('e = ',v)
print()
print('pi/4 = ',v)
print('pi = ', v * 4)
print()
print('fi = ',v)
print()
print('fi = ',v)
print()
print('gp = ',v)
print()
# end
//
Points of Interest
1. The value of the variable n is free so that the student can do experiments. In fact, it is possible to optimize the algorithms
using appropriate values of this variable;
2. The algorithms 1 and 3 were developed in 2 versions: a more readable and, therefore, more maintainable and a faster
version.
To calculate the Fibonacci numbers individually in the algorithm 3.0, we use the Binet formula.
3. There are some controversies about the performance of the while and for range control structures in Python. Since
version 3.0 the range structure has been improved and may be a good choice.
4. To calculate the Euler constant, we use the factorials . The factorial value tends to grow very quickly, so care must
be taken to avoid overflow errors.
Last Words
Thanks for reading!
I also made a version of these algorithms using the Haskell functional language. Look here:
https://www.codeproject.com/Tips/1265626/Working-with-numerical-lists-in-functional-languag
License
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)
é
https://www.codeproject.com/Tips/1264872/Algorithms-for-Calculating-Convergent-Series?display=Print 3/4
05/11/2018 Algorithms for Calculating Convergent Series - CodeProject
José Cintra
Software Developer
Brazil
I am a software developer focused on Mathematics, IoT and Games. In the free hours i also work as an IT Analyst and
Professor.
Homepage: HTML Apps
Blog: www.josecintra.com/blog
Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile Article Copyright 2018 by José Cintra
Web01-2016 | 2.8.180920.1 | Last Updated 4 Nov 2018 Everything else Copyright © CodeProject, 1999-2018
https://www.codeproject.com/Tips/1264872/Algorithms-for-Calculating-Convergent-Series?display=Print 4/4