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.

The maclaurin's series approximation for ln(1+x) is used to approximate ln(x) by detucting the maclaurin's series for ln(1-x). ln(1+x) - ln(1-x) = ln(1+x/1-x)and by letting y = (1+x/1-x), y could take any positive value.

y = 1+x/1-x, therefore x = y-1/y+1

-1 < x < 1

Python, 55 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
#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 : 10/07/10
#version :2.6

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


def maclaurin_ln(value, k):
    """
    Compute maclaurin's series approximation for ln(value).
    """
        
    first_value = 0.0
    
    #attempt to Approximate ln(x) for a given value    
    try:
        value_x = (value - 1)/float(value + 1)
        for item in xrange(1,k,2):
            next_value = value_x **item/item
            first_value += next_value
            
        return 2*(first_value)
    
    #Raise TypeError if input is not a number   
    except TypeError:
        print 'Please enter an integer or a float value'

if __name__ == "__main__":
    
    maclaurin_ln_1 = maclaurin_ln(2,100)
    print maclaurin_ln_1
    maclaurin_ln_2 = maclaurin_ln(5,100)
    print maclaurin_ln_2
    maclaurin_ln_3 = maclaurin_ln(777,10000)
    print maclaurin_ln_3
    print 
    for arg in xrange(7,28,10):
        print "ln(%s) = %s " %\
        (arg, maclaurin_ln(arg,10000))
###########################################################################

#"C: python \Maclaurin_ln
#0.69314718056
#1.60943791243
#6.65544035037

#ln(7) = 1.94591014906
#ln(17) = 2.83321334406
#ln(27) = 3.295836866

3 comments

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

Though, it will make a difference if others were confused!!!

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

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

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

Fouad Teniou (author) 12 years, 8 months ago  # | flag

A switch to C# and a new link

http://archive.msdn.microsoft.com/fouadteniou

Created by Fouad Teniou on Sat, 10 Jul 2010 (MIT)
Python recipes (4591)
Fouad Teniou's recipes (37)
Fouad Teniou Maclaurin's_series (17)

Required Modules

  • (none specified)

Other Information and Tasks