Skip to content
This repository was archived by the owner on Mar 21, 2021. It is now read-only.

Commit 5d6629d

Browse files
authored
Merge branch 'master' into master
2 parents feea742 + 4900f7b commit 5d6629d

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

Diff for: main.py

+28-16
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
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+
1218

1319
table = {}
1420

@@ -23,7 +29,8 @@ def simpson_rule():
2329
part2 += table[keys]
2430
elif keys % 2 != 0 and keys !=0 and keys !=n:
2531
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
2734
print(Integral)
2835
elif n%3 == 0:
2936
print("I'm Using Simpson's 3/8th Rule")
@@ -32,9 +39,9 @@ def simpson_rule():
3239
for keys in table:
3340
if keys % 3 == 0 and keys != 0 and keys != n:
3441
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:
3643
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)
3845
print(Integral)
3946

4047

@@ -46,7 +53,7 @@ def trapezoidal_rule():
4653
for keys in table:
4754
if keys!=0 and keys!=n:
4855
part1+=table[keys]
49-
Integral = h/2 * ((table[0] + table[n]) + 2*part1)
56+
Integral = h/2 * ((table[0] + table[final]) + 2*part1)
5057
print(Integral)
5158

5259

@@ -77,15 +84,20 @@ def find_degree():
7784
trapezoidal_rule()
7885

7986
def generate_y(limit):
87+
x = Limit0
8088
for i in range(int(limit+1)):
8189
counter = len(coefficient)
82-
temp = 0
83-
x = Limit0 + i
90+
temp = 0
8491
for j in coefficient:
8592
temp += int(j) * pow(x,counter)
8693
counter -= 1
8794
temp += constant
95+
x += h
8896
table[i] = temp
97+
global final
98+
final = i
99+
100+
89101
print(table)
90102

91103

0 commit comments

Comments
 (0)