@@ -18,9 +18,9 @@ def get_inputs() -> tuple:
1818 ('1/(1+x**2)', 1.0, -1.0)
1919 """
2020 func = input ("Enter function with variable as x: " )
21- a = float (input ("Enter lower limit: " ))
22- b = float (input ("Enter upper limit: " ))
23- return func , a , b
21+ lower_limit = float (input ("Enter lower limit: " ))
22+ upper_limit = float (input ("Enter upper limit: " ))
23+ return func , lower_limit , upper_limit
2424
2525
2626def safe_function_eval (func_str : str ) -> float :
@@ -32,7 +32,6 @@ def safe_function_eval(func_str: str) -> float:
3232
3333 Returns:
3434 float: The evaluated function result.
35-
3635 Examples:
3736 >>> f = safe_function_eval('x**2')
3837 >>> f(3)
@@ -54,14 +53,14 @@ def safe_function_eval(func_str: str) -> float:
5453 return lambda_func
5554
5655
57- def compute_table (func : str , a : float , b : float , acc : int ) -> tuple :
56+ def compute_table (func : str , lower_limit : float , upper_limit : float , acc : int ) -> tuple :
5857 """
5958 Compute the table of function values based on the limits and accuracy.
6059
6160 Args:
6261 func (str): The mathematical function with the variable 'x' as a string.
63- a (float): The lower limit of the integral.
64- b (float): The upper limit of the integral.
62+ lower_limit (float): The lower limit of the integral.
63+ upper_limit (float): The upper limit of the integral.
6564 acc (int): The number of subdivisions for accuracy.
6665
6766 Returns:
@@ -76,8 +75,8 @@ def compute_table(func: str, a: float, b: float, acc: int) -> tuple:
7675 """
7776 # Weddle's rule requires number of intervals as a multiple of 6 for accuracy
7877 n_points = acc * 6 + 1
79- h = (b - a ) / (n_points - 1 )
80- x_vals = np .linspace (a , b , n_points )
78+ h = (upper_limit - lower_limit ) / (n_points - 1 )
79+ x_vals = np .linspace (lower_limit , upper_limit , n_points )
8180
8281 # Evaluate function values at all points
8382 table = func (x_vals )
@@ -111,14 +110,14 @@ def apply_weights(table: list) -> list:
111110 return add
112111
113112
114- def compute_solution (add : list , table : list , h : float ) -> float :
113+ def compute_solution (add : list , table : list , step_size : float ) -> float :
115114 """
116115 Compute the final solution using the weighted values and table.
117116
118117 Args:
119118 add (list): A list of weighted values from apply_weights.
120119 table (list): A list of function values.
121- h (float): The step size (h) calculated from the limits and accuracy.
120+ step_size (float): The step size calculated from the limits and accuracy.
122121
123122 Returns:
124123 float: The final computed integral solution.
@@ -128,7 +127,7 @@ def compute_solution(add: list, table: list, h: float) -> float:
128127 ... -0.866, -1.0], 0.5235983333333333)
129128 0.7853975
130129 """
131- return 0.3 * h * (sum (add ) + table [0 ] + table [- 1 ])
130+ return 0.3 * step_size * (sum (add ) + table [0 ] + table [- 1 ])
132131
133132
134133if __name__ == "__main__" :
0 commit comments