Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13951

Problem filling up a list in the correct order while also avoiding duplicates in a recursive function for the adaptive Simpson's rule

$
0
0

I'm working on implementing the adaptive Simpson's rule for numerical integration in Python via a recursive function that iterates itself on the left and right side of an interval. In the algorithm, I have a vector named 'nodes' that stores the endpoints and midpoints of the subintervals. However, the algorithm begins filling 'nodes'in an unexpected way.Also the values start repeating themselves during the iteration

I tried messing around with the indexes of my vectors but got no luck. What I want is for the vectors to fill up with the extremes of the interval and then its mid-point then to iterate the same procedure for both side of the interval until a certain tolerance is met.This is my closing criteria:

if (abs(sab - fab)) / 15 <= tol:    integral += sab    if a not in nodes:        nodes.append(a)    if c not in nodes:        nodes.append(c)    if b not in nodes:        nodes.append(b)    return nodes, integralelse:    if a not in nodes:        nodes.append(a)    if c not in nodes:        nodes.append(c)    if b not in nodes:        nodes.append(b)    left_nodes, left_integral = recursive_integration(a, c, fa, fc, ac, tol/2, Lmin, nodes)    right_nodes, right_integral = recursive_integration(c, b, fc, fb, cb, tol/2, Lmin, nodes)    total_nodes = left_nodes + right_nodes    return total_nodes, left_integral + right_integral

Regarding the repetition I tried to implement this "somewhat" fix but i would like the function to fill it itself without an external manipulation

if a not in nodes:    nodes.append(a)if c not in nodes:    nodes.append(c)if b not in nodes:    nodes.append(b)

Viewing all articles
Browse latest Browse all 13951

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>