diff --git a/dynamic_programming/lucas_function.py b/dynamic_programming/lucas_function.py new file mode 100644 index 000000000000..f016e54d3a26 --- /dev/null +++ b/dynamic_programming/lucas_function.py @@ -0,0 +1,29 @@ +# Giving the output +def lucas_func(n): + # PREDFINING THE VALUES + a = 2 + b = 1 + + if n == 0: + return a + + # GENERATING THE NUMBER + for i in range(2, n + 1): + c = a + b + a = b + b = c + + return b + + +# USER INPUT +n = int(input("Enter the position n to find the nth Lucas Number: ")) +print(f"The {n}th Lucas Number is: {lucas_func(n)}") + +""" + +THE OUTPUT:- +Enter the position n to find the nth Lucas Number: 6 +The 6th Lucas Number is: 18 + +""" diff --git a/maths/area.py b/maths/area.py index 31a654206977..648afd04bf18 100644 --- a/maths/area.py +++ b/maths/area.py @@ -4,6 +4,8 @@ """ from math import pi, sqrt, tan +import numpy as np +from scipy.integrate import quad def surface_area_cube(side_length: float) -> float: @@ -264,6 +266,25 @@ def area_rectangle(length: float, width: float) -> float: return length * width +def area_of_parabola(x,a,b,c): + """ + Area under the parabola y = 1x² + 0x + 0 from x = 0 to x = 2 is 2.666666666666667 + """ + return a * x**2 + b * x + c + + def area_under_parabola(a, b, c, x1, x2): + area, _ = quad(parabola, x1, x2, args=(a, b, c)) + return area + #example usage + a = 1 + b = 0 + c = 0 + x1 = 0 + x2 = 2 + +area = area_under_parabola(a, b, c, x1, x2) +print(f"Area under the parabola y = {a}x² + {b}x + {c} from x = {x1} to x = {x2} is {area}") + def area_square(side_length: float) -> float: """ Calculate the area of a square.