Skip to content

Commit 1d6a3ba

Browse files
authored
Create trapezoidal_rule.py
1 parent 372ccb4 commit 1d6a3ba

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

trapezoidal_rule.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
Created on Sun Jul 23 15:25:19 2023
5+
6+
@author: sudipto3331
7+
"""
8+
9+
def fnc(x):
10+
return ((x*x))
11+
12+
a = float(input("Enter lower limit:"))
13+
b = float(input("Enter upper limit:"))
14+
n = int(input("Enter the number of N:"))
15+
16+
area = 0
17+
a_i = a
18+
diff = ((b-a)/n)
19+
20+
for i in range (1, n+1):
21+
b_i = a_i+((diff)*i)
22+
h = ((b_i-a))
23+
area = area + (h*((fnc(a)+fnc(b_i))/2))
24+
a = b_i
25+
26+
27+
print(area)

0 commit comments

Comments
 (0)