From 5478c493c66669e916f61018ddfc3b1be0ebb6b8 Mon Sep 17 00:00:00 2001 From: ASPP Student Date: Thu, 29 Jun 2023 14:36:36 -0600 Subject: [PATCH] Optimization Numerical Integration --- profiling/numerical_integration.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/profiling/numerical_integration.py b/profiling/numerical_integration.py index b96e209..ac8258f 100644 --- a/profiling/numerical_integration.py +++ b/profiling/numerical_integration.py @@ -1,5 +1,5 @@ import argparse - +import numpy as np import matplotlib.pyplot as plt @@ -21,13 +21,11 @@ def parse_arguments(): def integrate_f(f, a, b, n): - s = [] - for i in range(n): - dx = (b - a) / n - x = a + (i + 0.5) * dx - y = f(x) - s = s + [y * dx] - return sum(s) + dx = (b - a) / n + x = (np.arange(n) + 0.5) * dx + a + y = f(x) + s=y * dx + return np.sum(s) def measure_integration_errors(f, F, n_max, a, b):