You are on page 1of 6

Quadrature Formula.

wxm 1 / 6

kill(all);
done
f(x):=1/x;
1
f ( x ) :=
x
a:1;
b:2;
n:1;
h:(b−a)/n;
1
2
1
1
y:float((b−a)·(f(b)+f(a))/2);
0.75
y1:float(integrate(f(x),x,1,2));
0.6931471805599453
e:abs(y−y1);
0.05685281944005471
/*This is the observed error*/;
/*The theoretical error is -(b-a)^3*f''(ξ)/12 where a<ξ<b*/;
diff(f(x),x,2);
2
3
x
g(x):=2/(x^3);
2
g ( x ) :=
3
x
Quadrature Formula.wxm 2 / 6

/*Error bound is (b-a)^3/12 max a<ξ<b |f''(ξ)|*/;


wxplot2d(g(x),[x,1,2]);

/*As is evident from the graph that the max value of g(x)=f''(x) is attained at
as it is a decreasing function. So max 1<ξ<2 |f''(ξ)| is g(1)*/;
err_bound:float(((b−a)^3)·(g(1)/12));
0.1666666666666667

kill(all);
done
f(x):=1/x;
1
f ( x ) :=
x
a:1;
b:2;
n:2;
h:(b−a)/n;
1
2
2
1
2
y:float(((b−a)/6)·(f(a)+4·f((a+b)/2)+f(b)));
0.6944444444444444
y1:float(integrate(f(x),x,1,2));
0.6931471805599453
e:abs(y−y1);
0.001297263884499134
Quadrature Formula.wxm 3 / 6

/*This is the observed error*/;


/*The theoretical error is -(b-a)^5*f^(4)(ξ)/2880 where a<ξ<b*/;
diff(f(x),x,4);
24
5
x
g(x):=24/(x^5);
24
g ( x ) :=
5
x
/*Error bound is (b-a)^5/2880 max a<ξ<b |f^(4)(ξ)|*/;
wxplot2d(g(x),[x,1,2]);

/*As is evident from the graph that the max value of g(x)=f^(4)(x) is attained
as it is a decreasing function. So max 1<ξ<2 |f^(4)(ξ)| is g(1)*/;
err_bound:float(((b−a)^5)·(g(1)/2880));
0.008333333333333333

kill(all);
done
f(x):=%e^(−x);
−x
f ( x ) := %e
a:0;
b:1;
n:1;
h:(b−a)/n;
0
Quadrature Formula.wxm 4 / 6

1
1
1
y:float((b−a)·(f(b)+f(a))/2);
0.6839397205857212
y1:float(integrate(f(x),x,0,1));
0.6321205588285577
e:abs(y−y1);
0.0518191617571635
/*This is the observed error*/;
/*The theoretical error is -(b-a)^3*f''(ξ)/12 where a<ξ<b*/;
diff(f(x),x,2);
−x
%e
g(x):=%e^(−x);
−x
g ( x ) :=%e
/*Error bound is (b-a)^3/12 max a<ξ<b |f''(ξ)|*/;
wxplot2d(g(x),[x,0,1]);

/*As is evident from the graph that the max value of g(x)=f''(x) is attained at
as it is a decreasing function. So max 0<ξ<1 |f''(ξ)| is g(0)*/;
err_bound:float(((b−a)^3)·(g(0)/12));
0.08333333333333333

kill(all);
done
f(x):=%e^(−x);
Quadrature Formula.wxm 5 / 6

−x
f ( x ) := %e
a:0;
b:1;
n:2;
h:(b−a)/n;
0
1
2
1
2
y:float(((b−a)/6)·(f(a)+4·f((a+b)/2)+f(b)));
0.6323336800036626
y1:float(integrate(f(x),x,0,1));
0.6321205588285577
e:abs(y−y1);
−4
2.131211751049689 10
/*This is the observed error*/;
/*The theoretical error is -(b-a)^5*f^(4)(ξ)/2880 where a<ξ<b*/;
diff(f(x),x,4);
−x
%e
g(x):=%e^(−x);
−x
g ( x ) :=%e
/*Error bound is (b-a)^5/2880 max a<ξ<b |f^(4)(ξ)|*/;
wxplot2d(g(x),[x,0,1]);

/*As is evident from the graph that the max value of g(x)=f^(4)(x) is attained
as it is a decreasing function. So max 0<ξ<1 |f^(4)(ξ)| is g(0)*/;
Quadrature Formula.wxm 6 / 6

err_bound:float(((b−a)^5)·(g(0)/2880));
−4
3.472222222222223 10

You might also like