Chapter 6. Quadrature - MathWorks
Chapter 6. Quadrature - MathWorks
Chapter 6. Quadrature - MathWorks
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
<strong>6.</strong>5. Performance 9<br />
calls for linear algebraic vector operations that are not appropriate here. The Matlab<br />
function vectorize transforms a scalar expression into something that can be<br />
used as an argument to function functions.<br />
Many of the function functions in Matlab require the specification of an<br />
interval of the x-axis. Mathematically, we have two possible notations, a ≤ x ≤ b<br />
or [a, b]. With Matlab, we also have two possibilities. The endpoints can be given<br />
as two separate arguments, a and b, or can be combined into one vector argument,<br />
[a,b]. The quadrature functions quad and quadl use two separate arguments. The<br />
zero finder, fzero, uses a single argument because either a single starting point or<br />
a two-element vector can specify the interval. The ordinary differential equation<br />
solvers that we encounter in the next chapter also use a single argument because a<br />
many-element vector can specify a set of points where the solution is to be evaluated.<br />
The easy plotting function, ezplot, accepts either one or two arguments.<br />
<strong>6.</strong>5 Performance<br />
The Matlab demos directory includes a function named humps that is intended<br />
to illustrate the behavior of graphics, quadrature, and zero-finding routines. The<br />
function is<br />
The statement<br />
h(x) =<br />
ezplot(@humps,0,1)<br />
1<br />
(x − 0.3) 2 + 0.01 +<br />
1<br />
(x − 0.9) 2 + 0.04 .<br />
produces a graph of h(x) for 0 ≤ x ≤ 1. There is a fairly strong peak near x = 0.3<br />
and a more modest peak near x = 0.9.<br />
The default problem for quadgui is<br />
quadgui(@humps,0,1,1.e-4)<br />
You can see in Figure <strong>6.</strong>3 that with this tolerance, the adaptive algorithm has<br />
evaluated the integrand 93 times at points clustered near the two peaks.<br />
With the Symbolic Toolbox, it is possible to analytically integrate h(x). The<br />
statements<br />
syms x<br />
h = 1/((x-.3)^2+.01) + 1/((x-.9)^2+.04) - 6<br />
I = int(h)<br />
produce the indefinite integral<br />
I = 10*atan(10*x-3)+5*atan(5*x-9/2)-6*x<br />
The statements<br />
D = simple(int(h,0,1))<br />
Qexact = double(D)<br />
produce a definite integral