-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlongprocessintegration.py
More file actions
115 lines (112 loc) · 2.61 KB
/
longprocessintegration.py
File metadata and controls
115 lines (112 loc) · 2.61 KB
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
from math import sin, cos, tan, pi
print "This intergration program works for dx function with expression having only one variable of x and does not work for trignometric functions"
a=float(raw_input("enter the lower limit\n"));
b=float(raw_input("enter the upper limit\n"));
expr=raw_input("Enter the expression\n");
def convert_to_pow(str):
(b1,b2)=str.split('^',1)
if b1[-1]!=')' and b2[0]!='(':
count=-1
c=''
for i in range(0,len(b1)):
if b1[count-i]=='+' or b1[count-i]=='-' or b1[count-i]=='*' or b1[count-i]=='/' or b1[count-i]=='^' or b1[count-i]=='(' or b1[count-i]==')':
break;
else:
c=b1[count-i]+c
d=''
for i in range(0,len(b2)):
if b2[i]=='+' or b2[i]=='-' or b2[i]=='*' or b2[i]=='/' or b2[i]=='^' or b2[i]=='w' or b2[i]=='(' or b2[i]==')':
break;
else:
d=d+b2[i]
b1=b1.__getslice__(0,len(b1)-len(c))
b2=b2.__getslice__(len(d),len(b2))
b=b1+"pow("+c+","+d+")"+b2
return b
if b1[-1]!=')' and b2[0]=='(':
count=-1
c=''
for i in range(0,len(b1)):
if b1[count-i]=='+' or b1[count-i]=='-' or b1[count-i]=='*' or b1[count-i]=='/' or b1[count-i]=='^' or b1[count-i]=='w' or b1[count-i]=='n':
break;
else:
c=b1[count-i]+c
d='('
i=1
level=1
while(level!=0):
if b2[i]=='(':
level=level+1
if b2[i]==')':
level=level-1
d=d+b2[i]
i=i+1
b1=b1.__getslice__(0,len(b1)-len(c))
b2=b2.__getslice__(len(d),len(b2))
b=b1+"pow("+c+","+d+")"+b2
return b
if b1[-1]==')' and b2[0]!='(':
c=')'
i=-2
level=1
while(level!=0):
if b1[i]==')':
level=level+1
if b1[i]=='(':
level=level-1
c=b1[i]+c
i=i-1
d=''
for i in range(0,len(b2)):
if b2[i]=='+' or b2[i]=='-' or b2[i]=='*' or b2[i]=='/' or b2[i]=='s' or b2[i]=='p' or b2[i]=='w':
break;
else:
d=d+b2[i]
b1=b1.__getslice__(0,len(b1)-len(c))
b2=b2.__getslice__(len(d),len(b2))
b=b1+"pow("+c+","+d+")"+b2
return b
if b1[-1]==')' and b2[0]=='(':
c=')'
count=-1
i=-2
level=1
while(level!=0):
if b1[i]==')':
level=level+1
if b1[i]=='(':
level=level-1
c=b1[i]+c
i=i-1
d='('
i=1
level=1
while(level!=0):
if b2[i]=='(':
level=level+1
if b2[i]==')':
level=level-1
d=d+b2[i]
i=i+1
b1=b1.__getslice__(0,len(b1)-len(c))
b2=b2.__getslice__(len(d),len(b2))
b=b1+"pow("+c+","+d+")"+b2
return b
for i in range(0, len(expr)-2):
if '^' in expr:
expr=convert_to_pow(expr)
count = 0
h=(b-a)/6
c=[]
d=[]
for b in range(0,7):
c.append(a)
a=a+h
for b in range(0,7):
c[b]=str(c[b])
d.append(expr.replace("x", c[b]))
for b in range(0,7):
c[b]=eval(d[b])
ans=(3*h)/10
ans=ans*(c[0]+5*c[1]+c[2]+6*c[3]+c[4]+5*c[5]+c[6])
print ans