27.12.2012 Views

Wave Propagation in Linear Media | re-examined

Wave Propagation in Linear Media | re-examined

Wave Propagation in Linear Media | re-examined

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

7.5 Test of the quadratu<strong>re</strong> rout<strong>in</strong>e<br />

7.5 Test of the quadratu<strong>re</strong> rout<strong>in</strong>e<br />

We now want to apply our quadratu<strong>re</strong> rout<strong>in</strong>e to some of the test functions that a<strong>re</strong> commonly<br />

used <strong>in</strong> the literatu<strong>re</strong>. The objective of such benchmarks usually is to exam<strong>in</strong>e how<br />

many evaluations of the <strong>in</strong>tegrand function a given algorithm needs to <strong>re</strong>turn a <strong>re</strong>sult of the<br />

<strong>re</strong>qui<strong>re</strong>d accuracy. The number of function evaluations is <strong>in</strong> turn a measu<strong>re</strong> for the e ectiveness<br />

of compet<strong>in</strong>g algorithms. In the case of our quadratu<strong>re</strong> rout<strong>in</strong>e, however, we obta<strong>in</strong> no<br />

<strong>in</strong>formation how often Mathematica needs to evaluate the <strong>in</strong>tegrand for its <strong>in</strong>ternal computations.<br />

All we can test is the accuracy of the <strong>re</strong>sult depend<strong>in</strong>g on the sett<strong>in</strong>gs of the algorithm<br />

parameters. So the ma<strong>in</strong> goal of this section is to verify that the algorithm works cor<strong>re</strong>ctly<br />

rather than to compa<strong>re</strong> it with other rout<strong>in</strong>es.<br />

As the execution time of the rout<strong>in</strong>e is not our ma<strong>in</strong> concern he<strong>re</strong>, we do not use explicit<br />

enumeration functions that de ne the partition po<strong>in</strong>ts for the quadratu<strong>re</strong>. We just specify<br />

the argument function of the oscillat<strong>in</strong>g factors of the <strong>in</strong>tegrand and leave the determ<strong>in</strong>ation<br />

of the appropriate subdivision of the <strong>in</strong>tegration range to Mathematica.<br />

Remark (Pu<strong>re</strong> functions) To avoid unnecessary declarations, we use pu<strong>re</strong> functions<br />

[140] to specify the functions that a<strong>re</strong> needed to compute the partition. In such a function<br />

the places whe<strong>re</strong> the <strong>in</strong>dependent variables a<strong>re</strong> to be <strong>in</strong>serted upon evaluation a<strong>re</strong> marked<br />

with slots (#, ##, #1, ::: ), the function itself is de ned as pu<strong>re</strong> by a trail<strong>in</strong>g ampersand (&).<br />

So while we would de ne a quadratic polynomial <strong>in</strong> full notation as p[x_] := x^2 + 3 x,<br />

we write the pu<strong>re</strong> function as (#^2 + 3 #)&. This concept enables us to write very<br />

compact code, but it is useful only if the function is not <strong>re</strong>qui<strong>re</strong>d to have a name.<br />

Prior to test<strong>in</strong>g we must load the package.<br />

In[12]:=

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!