Skip to content

Commit a22205a

Browse files
Update area.py
1 parent c3d4b9e commit a22205a

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

maths/area.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
"""
55

66
from math import pi, sqrt, tan
7+
import numpy as np
8+
from scipy.integrate import quad
79

810

911
def surface_area_cube(side_length: float) -> float:
@@ -264,6 +266,25 @@ def area_rectangle(length: float, width: float) -> float:
264266
return length * width
265267

266268

269+
def area_of_parabola(x,a,b,c):
270+
"""
271+
Area under the parabola y = 1x² + 0x + 0 from x = 0 to x = 2 is 2.666666666666667
272+
"""
273+
return a * x**2 + b * x + c
274+
275+
def area_under_parabola(a, b, c, x1, x2):
276+
area, _ = quad(parabola, x1, x2, args=(a, b, c))
277+
return area
278+
#example usage
279+
a = 1
280+
b = 0
281+
c = 0
282+
x1 = 0
283+
x2 = 2
284+
285+
area = area_under_parabola(a, b, c, x1, x2)
286+
print(f"Area under the parabola y = {a}x² + {b}x + {c} from x = {x1} to x = {x2} is {area}")
287+
267288
def area_square(side_length: float) -> float:
268289
"""
269290
Calculate the area of a square.

0 commit comments

Comments
 (0)