@@ -14,15 +14,15 @@ def taylorexpansion(func, a, n, var):
14
14
k = 1
15
15
while (k < n ):
16
16
d = diff (d , var )
17
- term = (d * ((t_y - a ) ** k ))/ factorial (k )
17
+ term = (d * ((t_y - a ) ** k )) / factorial (k )
18
18
term = term .subs (var , a )
19
19
if (term == 0 ):
20
20
continue
21
21
term = term .subs (t_y , var )
22
- expansion = term + expansion
22
+ expansion = term + expansion
23
23
k += 1
24
24
if (d == 0 and k < n ):
25
- print ("only " , k - 1 , " terms present" )
25
+ print ("only " , k - 1 , " terms present" )
26
26
if (n < 1 ):
27
27
print ("3rd argument is for no. of terms, provide a natural number" )
28
28
return ''
@@ -54,16 +54,16 @@ def examples():
54
54
print (taylorvalue (exp (x ), 1 , 10 , x ))
55
55
56
56
# log(1+x) expansion at x=0 with 5 terms differentiating with respect to x
57
- pprint (taylorexpansion (log (x + 1 ), 0 , 5 , x ))
57
+ pprint (taylorexpansion (log (x + 1 ), 0 , 5 , x ))
58
58
59
59
# sin(x) expansion at x=0 with 5 terms differentiating with respect to x
60
60
pprint (taylorexpansion (sin (x ), 0 , 5 , x ))
61
61
62
62
# expansion for expression at x=0 with 3 terms differentiating wrt to x
63
- pprint (taylorexpansion ((5 * x ** 2 ) + ( 3 * x ) + (7 ), 0 , 3 , x ))
63
+ pprint (taylorexpansion ((5 * x ** 2 ) + ( 3 * x ) + (7 ), 0 , 3 , x ))
64
64
65
65
# e^(xy) expansion at x=1 with 5 terms differentiating with respect to x
66
- pprint (taylorexpansion (exp (x * y ), 1 , 5 , x ))
66
+ pprint (taylorexpansion (exp (x * y ), 1 , 5 , x ))
67
67
68
68
69
69
examples ()
0 commit comments