Numerical Integration - Python

This is what i need help with

Next time posting code, post it as text. You make it hard to copy and paste code.

  • In the function f(), you pass in one variable, called x. In the function you use h, a and b. Those will not be available, they are not passed in nor a local variable. You are saying that your function only depends on one parameter, so make it so.

  • The same for the function trapezium. Suddenly you use variables xb and h which are not passed in, nor a local variable.

  • The idea of the algorithm is that you calculate the function for points that are h units apart, so I think you mean the first line of your trapezium function to read h = (xn - x0) / n. Now h is a local variable and the “x-distance” between points.

  • The number of points in range(1, n - 1) is n - 1 and not n.

The remainder looks OK.

1 Like