1
1
def get_values ():
2
- global L , LimitN , Limit0 , h ,constant ,n
3
- coefficient = str (input ("Enter the co-efficient of the integrand F(x): " ))
4
- Limit0 = int (input ("Enter the Lower Limit: " ))
5
- LimitN = int (input ("Enter the Upper Limit: " ))
6
- h = 0.5
7
- L = coefficient .split ()
8
- constant = int (input ("Enter Constant: " ))
9
- n = (LimitN - Limit0 )/ h
10
- print (type (n ))
11
- print ("Test" )
2
+ try :
3
+ global L , LimitN , Limit0 , h ,constant ,n
4
+ coefficient = str (input ("Enter the co-efficient of the integrand F(x): " ))
5
+ Limit0 = int (input ("Enter the Lower Limit: " ))
6
+ LimitN = int (input ("Enter the Upper Limit: " ))
7
+ h = float (input ("Enter the value of h: " ))
8
+ L = coefficient .split ()
9
+ constant = int (input ("Enter Constant: " ))
10
+ n = (LimitN - Limit0 )/ h
11
+ except Exception as e :
12
+ print ("Oops! Value Error Occurred." )
13
+ print ("Try Again !!\n \n " )
14
+
15
+ get_values ()
16
+
17
+
12
18
13
19
table = {}
14
20
@@ -23,7 +29,8 @@ def simpson_rule():
23
29
part2 += table [keys ]
24
30
elif keys % 2 != 0 and keys != 0 and keys != n :
25
31
part1 += table [keys ]
26
- Integral = h / 3 * ((table [0 ] + table [n ]) + 4 * part1 + 2 * part2 )
32
+ Integral = ((table [0 ] + table [final ]) + 4 * part1 + 2 * part2 )
33
+ Integral = Integral * h / 3
27
34
print (Integral )
28
35
elif n % 3 == 0 :
29
36
print ("I'm Using Simpson's 3/8th Rule" )
@@ -32,9 +39,9 @@ def simpson_rule():
32
39
for keys in table :
33
40
if keys % 3 == 0 and keys != 0 and keys != n :
34
41
part2 += table [keys ]
35
- elif keys % 2 != 0 and keys != 0 and keys != n :
42
+ elif keys % 3 != 0 and keys != 0 and keys != n :
36
43
part1 += table [keys ]
37
- Integral = 3 * h / 8 * ((table [0 ] + table [n ]) + 3 * part1 + 2 * part2 )
44
+ Integral = 3 * h / 8 * ((table [0 ] + table [final ]) + 3 * part1 + 2 * part2 )
38
45
print (Integral )
39
46
40
47
@@ -46,7 +53,7 @@ def trapezoidal_rule():
46
53
for keys in table :
47
54
if keys != 0 and keys != n :
48
55
part1 += table [keys ]
49
- Integral = h / 2 * ((table [0 ] + table [n ]) + 2 * part1 )
56
+ Integral = h / 2 * ((table [0 ] + table [final ]) + 2 * part1 )
50
57
print (Integral )
51
58
52
59
@@ -77,15 +84,20 @@ def find_degree():
77
84
trapezoidal_rule ()
78
85
79
86
def generate_y (limit ):
87
+ x = Limit0
80
88
for i in range (int (limit + 1 )):
81
89
counter = len (coefficient )
82
- temp = 0
83
- x = Limit0 + i
90
+ temp = 0
84
91
for j in coefficient :
85
92
temp += int (j ) * pow (x ,counter )
86
93
counter -= 1
87
94
temp += constant
95
+ x += h
88
96
table [i ] = temp
97
+ global final
98
+ final = i
99
+
100
+
89
101
print (table )
90
102
91
103
0 commit comments