Professional Documents
Culture Documents
17 April Composite Trapezoid
17 April Composite Trapezoid
f[x_] = 1 / (1 + x ^ 2);
a = 0;
b = 1;
n = 4;
h = (b - a) / n;
apprint = (h / 2) (f[a] + 2 * Sum[f[a + i * h], {i, 1, n - 1}] + f[b]);
exctint = Integrate[f[x], {x, a, b}];
numerror = Abs[exctint - apprint];
Print["Approximate int using Composite trapezoid = ", N[apprint]];
Print["Exact int = ", N[exctint]];
Print["Numerical error = ", N[numerror]];