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 to approximate ( 1+x)^m is known as a binomial series.
However, if m is a an integer and m >= 0 the function f(x ) = (1+x)^m is a polynomial function of degree m and it will converge for all the values of x on the interval ]-inf, +inf [, otherwise it will converge to (1+x)^m only for the values of x on the interval ]-1,1[, thus, the convergence of x will depend on the value of m
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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | #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_binomial is a function to compute(1+x)^m using maclaurin
binomial series and the interval of convergence is -1 < x < 1
(1+x)^m = 1 + mx + m(m-1)x^2/2! + m(m-1)(m-2)x^3/3!...........
note: if m is a nonegative integer the binomial is a polynomial of
degree m and it is valid on -inf < x < +inf,thus, the error function
will not be valid.
"""
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_binomial(value,m,k):
"""
Compute maclaurin's binomial series approximation for (1+x)^m.
"""
global first_value
first_value = 0.0
error(value)
#attempt to Approximate (1+x)^m for given values
try:
for item in xrange(1,k):
next_value =m*(value**item)/factorial(item)
for i in range(2,item+1):
next_second_value =(m-i+1)
next_value *= next_second_value
first_value += next_value
return first_value + 1
#Raise TypeError if input is not within
#the interval of convergence
except TypeError,exception:
print exception
#Raise OverflowError if an over flow occur
except OverflowError:
print '\n<Please enter a lower k value to avoid the Over flow\n '
if __name__ == "__main__":
maclaurin_binomial_1 = maclaurin_binomial(0.777,-0.5,171)
print maclaurin_binomial_1
maclaurin_binomial_2 = maclaurin_binomial(0.37,0.5,171)
print maclaurin_binomial_2
maclaurin_binomial_3 = maclaurin_binomial(0.3,0.717,171)
print maclaurin_binomial_3
########################################################################
#c:python
#
#0.750164116353
#1.17046999107
#1.20697252357
#######################################################################
#Version : Python 3.2
#import math
#def maclaurin_binomial(value,m,k):
# """
# Compute maclaurin's binomial series approximation for (1+x)^m.
# """
# global first_value
# first_value = 0.0
#
# #attempt to Approximate (1+x)^m for given values
# try:
#
# for item in range(1,k):
# next_value =m*(value**item)/math.factorial(item)
#
# for i in range(2,item+1):
# next_second_value =(m-i+1)
# next_value *= next_second_value
# first_value += next_value
# return first_value + 1
#
# #Raise TypeError if input is not within
# #the interval of convergence
# except TypeError as exception:
# print (exception)
#
# #Raise OverflowError if an over flow occur
# except OverflowError:
# print ('\n<Please enter a lower k value to avoid the Over flow\n ')
#
#
#if __name__ == "__main__":
# maclaurin_binomial_1 = maclaurin_binomial(0.777,-0.5,171)
# print (maclaurin_binomial_1 )
# maclaurin_binomial_2 = maclaurin_binomial(0.37,0.5,171)
# print (maclaurin_binomial_2)
# maclaurin_binomial_3 = maclaurin_binomial(0.3,0.717,171)
# print (maclaurin_binomial_3)
######################################################################################
#decimal Version Python 3.2
#from math import *
#from decimal import Decimal as D,Context, localcontext
#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_binomial(value,m,k):
# """
# Compute maclaurin's binomial series approximation for (1+x)^m.
# """
# global first_value
# first_value = 0
#
# #attempt to Approximate (1+x)^m for given values
# try:
#
# for item in range(1,k):
# next_value = (m*(value**item))/factorial(item)
# for i in range(2,item+1):
# next_second_value =(m-i+1)
# next_value *= next_second_value
# first_value += next_value
#
# return (first_value) + (1)
#
# #Raise TypeError if input is not within
# #the interval of convergence
# except TypeError as exception:
# print(exception)
#
# #Raise OverflowError if an over flow occur
# except OverflowError:
# print('\n<Please enter a lower k value to avoid the Over flow\n ')
#
#
#if __name__ == "__main__":
#
# with localcontext(Context(prec= 1777)):
# for arg in range(2,-8,-2):
# print(maclaurin_binomial(D("0.777"),arg,171))
|
My profile,poems, photos,and design's links
https://acrobat.com/#d=aEjxtq78QkGKUxa*UprkZQ
A switch to C# and a new link
http://archive.msdn.microsoft.com/fouadteniou