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, 81 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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81``` ```#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 : 15/07/10 #version :2.6 from decimal import Decimal as D,Context, localcontext def maclaurin_ln(value, k): """ Compute maclaurin's series approximation for ln(value). """ first_value = 0 #attempt to Approximate ln(x) for a given value try: value_x = (value - D("1.0"))/(value + D("1.0")) 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__": with localcontext(Context(prec=67)): for arg in xrange(7,28,10): print "ln(%s) = %s " %\ (arg, maclaurin_ln(arg,D("10000"))) ####################################################################### #FT "C:\Maclaurin_lndecimal1.py" #ln(7) = 1.945910149055313305105352743443179729637084729581861188459390149937 #ln(17) = 2.833213344056216080249534617873126535588203012585744787297237737878 #ln(27) = 3.295836866004329074185735710767577113942471673468248355204083000896 ########################################################################################## Version : Python 3.2 #from decimal import Decimal as D #from decimal import * #from math import * #def maclaurin_ln(value, k): # """ # Compute maclaurin's series approximation for ln(value). # """ # global first_value # first_value = 0 # # #attempt to Approximate ln(x) for a given value # try: # value_x = (value - 1)/(value + 1) # for item in range(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__": # # # with localcontext(Context(prec=170)): # for arg in range(7,28,10): # print("ln(%s) = %s " %\ # (arg, maclaurin_ln(D(arg),10000))) # getcontext().prec = 17 # for arg in range(7,28,10): # # print("ln(%s) = %s " %\ # (arg, maclaurin_ln(D(arg),10000))) ```

#### 1 comment Fouad Teniou (author) 11 years, 2 months ago Created by Fouad Teniou on Thu, 15 Jul 2010 (MIT)