Skip to content

Commit 3941c0b

Browse files
committed
flake8 linting
1 parent e02b8e9 commit 3941c0b

File tree

1 file changed

+44
-39
lines changed

1 file changed

+44
-39
lines changed

taylor_mclaurian_expansion/main.py

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,69 @@
1-
import math
2-
from sympy import *
1+
from sympy import symbols, factorial, diff, pprint, exp, log, sin
32

43
x = symbols('x')
54
y = symbols('y')
65

7-
def taylorexpansion(func,a,n,var):
6+
7+
def taylorexpansion(func, a, n, var):
88
t_y = symbols('t_y')
9-
expansion = func.subs(var,a)
9+
expansion = func.subs(var, a)
1010
d = func
11-
if(expansion==0):
12-
n+=1
11+
if (expansion == 0):
12+
n += 1
1313
try:
14-
k=1
15-
while (k<n):
16-
d = diff(d,var)
14+
k = 1
15+
while (k < n):
16+
d = diff(d, var)
1717
term = (d*((t_y-a)**k))/factorial(k)
18-
term = term.subs(var,a)
19-
if(term==0):
18+
term = term.subs(var, a)
19+
if (term == 0):
2020
continue
21-
term = term.subs(t_y,var)
22-
expansion=term+expansion
23-
k+=1
24-
if(d==0 and k<n):
25-
print("only ",k-1," terms present")
26-
if n<1:
27-
print("3rd argument denotes number of terms and should be a natural number")
21+
term = term.subs(t_y, var)
22+
expansion = term+expansion
23+
k += 1
24+
if (d == 0 and k < n):
25+
print("only ", k-1, " terms present")
26+
if (n < 1):
27+
print("3rd argument is for no. of terms, provide a natural number")
2828
return ''
29-
expansion = expansion.subs(t_y,var)
29+
expansion = expansion.subs(t_y, var)
3030
return expansion
3131
except TypeError:
32-
print("3rd argument denotes number of terms and should be a natural number")
32+
print("3rd argument denotes number of terms, provide a natural number")
3333
return ''
3434

35-
def taylorvalue(func,a,n,x):
36-
f=taylorexpansion(func,a,n,x)
37-
return f.evalf(subs={x:a})
3835

39-
def mclaurianexpansion(func,steps,variable):
40-
taylorexpansion(func,0,steps,variable)
36+
def taylorvalue(func, a, n, x):
37+
f = taylorexpansion(func, a, n, x)
38+
return f.evalf(subs={x: a})
39+
40+
41+
def mclaurianexpansion(func, steps, variable):
42+
taylorexpansion(func, 0, steps, variable)
43+
44+
45+
def mclaurianvalue(func, steps, variable):
46+
taylorvalue(func, 0, steps, variable)
4147

42-
def mclaurianvalue(func,steps,variable):
43-
taylorvalue(func,0,steps,variable)
4448

4549
def examples():
46-
# e^x expansion at point x=0 with 5 terms differentiating with respect to x
47-
pprint(taylorexpansion(exp(x),0,5,x))
50+
# e^x expansion at x=0 with 5 terms differentiating with respect to x
51+
pprint(taylorexpansion(exp(x), 0, 5, x))
52+
53+
# e^x approximation at x=1 with 10 terms differentiating with respect to x
54+
print(taylorvalue(exp(x), 1, 10, x))
4855

49-
# e^x approximation at point x=1 with 10 terms differentiating with respect to x
50-
print(taylorvalue(exp(x),1,10,x))
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))
5158

52-
# log(1+x) expansion at point x=0 with 5 terms differentiating with respect to x
53-
pprint(taylorexpansion(log(x+1),0,5,x))
59+
# sin(x) expansion at x=0 with 5 terms differentiating with respect to x
60+
pprint(taylorexpansion(sin(x), 0, 5, x))
5461

55-
# sin(x) expansion at point x=0 with 5 terms differentiating with respect to x
56-
pprint(taylorexpansion(sin(x),0,5,x))
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))
5764

58-
# expansion for expression at point x=0 with 3 terms differentiating with respect to x
59-
pprint(taylorexpansion((5*x**2)+(3*x)+(7),0,3,x))
65+
# e^(xy) expansion at x=1 with 5 terms differentiating with respect to x
66+
pprint(taylorexpansion(exp(x*y), 1, 5, x))
6067

61-
# e^(xy) expansion at point x=1 with 5 terms differentiating with respect to x
62-
pprint(taylorexpansion(exp(x*y),1,5,x))
6368

6469
examples()

0 commit comments

Comments
 (0)