Welcome, guest | Sign In | My Account | Store | Cart

C. Maclaurin. A Scottish mathematician gained his master degree at age 17, and his major mathematics' work arise from his special knowledge in Newton's ideas and the formulation of Newton's methods.

However, C. Maclaurin also contributed to the astronomy science and helped to improve maps and invented some mechanical devices.

My mathematics python's programs is a set of Maclaurin's series to compute some of the most important functions in calculus.

Though, the computation of an infinite sum which give the value of a function in terms of the derivatives evaluated at a special case where x0 = 0,in contrast with Taylor series.

Maclaurin's series for tan-1 function is achieved by integrating the function f(x)= 1/(1+x^2). However, this approach could be used to find Maclaurin's series for others functions.

Python, 59 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#On the name of ALLAH and may the blessing and peace of Allah 
#be upon the Messenger of Allah Mohamed Salla Allahu Aliahi Wassalam.
#Author : Fouad Teniou
#Date : 06/07/10
#version :2.6

"""
maclaurin_tan-1 is a function to compute tan-1(x) using maclaurin series
and the interval of convergence is -1 <= x <= +1
sin(x) = x - x^3/3 + x^5/5 - x^7/7 ...........
"""

from math import *

def error(number):
    """ Raises interval of convergence error."""
    
    if number > 1 or number < -1 :
        raise TypeError,\
            "\n<The interval of convergence should be -1 <= value <= 1 \n"

def maclaurin_cot(value, k):
    """
    Compute maclaurin's series approximation for tan-1(x)
    """
    global first_value    
    first_value = 0.0
    
    #attempt to Approximate tan-1(x) for a given value 
    try:
        error(value)
        for item in xrange(1,k,4):
            next_value = value**item/float(item)
            first_value += next_value
            
        for arg in range(3,k,4):
            next_value = -1* value **arg/float(arg)
            first_value += next_value
            
        return round(first_value*180/pi,2)
    
    #Raise TypeError if input is not within
    #the interval of convergence
    except TypeError,exception:
        print exception 

if __name__ == "__main__":
    
    maclaurin_cot1 = maclaurin_cot(0.305730681,100)
    print maclaurin_cot1
    maclaurin_cot2 = maclaurin_cot(0.75355405,100)
    print maclaurin_cot2
    maclaurin_cot3 = maclaurin_cot(0.577350269,100)
    print maclaurin_cot3
#################################################################
#"C:\python
#17.0
#37.0
#30.0

1 comment

Fouad Teniou (author) 13 years, 7 months ago  # | flag

My profile,poems, photos,and design's links

https://acrobat.com/#d=aEjxtq78QkGKUxa*UprkZQ