6

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

In[1]:= f[x_] := x + Exp[- x ^ 2];

a = - 1;
b = 2;
h = b - a;
c = h / 2 (f[a] + f[b]);
int = Integrate[x + Exp[- x ^ 2], {x, - 1, 2}]
Print["The area approximatedvalue by Trapezoidal rule is ", N[c]]
Print["Original valueof the integral is ",
N[int], "and the error is ", Abs[N[c] - N[int]]]
1
Out[6]= 3 + π (Erf[1] + Erf[2])
2

The area approximatedvalue by Trapezoidal rule is 2.07929

Original valueof the integral is 3.12891and the error is 1.04961

In[17]:= f[x_] := x + Exp[- x ^ 2];


a = - 1;
b = 2;
h = (b - a) / 2;
c = h / 3 (f[a] + 4 f[a + h] + f[b]);
int = Integrate[x + Exp[- x ^ 2], {x, - 1, 2}]
Print["The area approximated value Simpson Rule is ", N[c]]
Print["Original value of the integral is ",
N[int], " and the arror is ", Abs[N[c] - N[int]]]
1
Out[22]= 3 + π (Erf[1] + Erf[2])
2

The area approximated value Simpson Rule is 3.2507

Original value of the integral is 3.12891 and the arror is 0.121794

You might also like