# How to do this numerical integration via Simpson’s rule?

this is the question. Develop a code to perform a numerical integration for the following functions using Simpson’s rule. You must implement the algorithm in the form of a Module[ ]. Partition the domain of integration [𝑎, 𝑏] into 𝑁𝑥 = 250 subintervals.

this is the equation

𝑓 (𝑥) = sin 𝑥 tanh 𝑥 for 𝑥 ∈ [0, 𝜋].

so I did the first coding

f[x_] := Sin[x]*Tanh[x];
Integrate[f[x], {x, a, b}];
a = 0.0;
b = 1.0*Pi;
simpson[a_, b_, f_] := Module[{},
Nx = 250;
Deltax = (b - a)/Nx;
x[0] = a;
x[i_] := x[0] + i*Deltax;


then I dont know what to do after this, and I'm not sure if my coding is right or wrong. anyone help

• (in the interest of not doing your homework for you...). A very procedural way of solving this is to define a "local" variable in the first argument of Module, and then use a loop (e.g., Do[] ) to increment that value (rather than defining a set of delayed rules). A more functional way might use a function map over a list of possible x values. – Joshua Schrier May 6 at 14:59
• Simpson's rule has been often discussed and often implemented on this site already – Michael E2 May 6 at 15:01