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 Mathematica implementation of a quadratu<strong>re</strong> function<br />

If[N[zeros[[1]]] < N[a],<br />

zeros = Select[zeros,(N[#] >= N[a])&];<br />

Message[OscInt::lowfirst,Length[zeros]]];<br />

If[N[zeros[[1]]] == N[a], 0,<br />

NIntegrate[f[x],fx,a,zeros[[1]]g,<br />

Method->DoubleExponential]] +<br />

If[N[zeros[[1]]] == Inf<strong>in</strong>ity, 0,<br />

seqtab = Table[NIntegrate[f[x],fx,zeros[[i]],zeros[[i+1]]g,<br />

Method->GaussKronrod],<br />

fi,1,Length[zeros]-1g];<br />

SequenceLimit[Take[FoldList[Plus,0,seqtab],-ne],WynnDeg<strong>re</strong>e->wd]]<br />

7.3.6 OscIntControlled<br />

This function is probably the most <strong>in</strong>tricate of the package. It is basically a copy ofPartInt<br />

extended by a control loop. The user <strong>in</strong>terface is exactly the same as that of OscInt, it is<br />

<strong>in</strong>voked by<br />

OscIntControlled[f, fzero, a, opts].<br />

The only di e<strong>re</strong>nce <strong>in</strong> the behaviour towards the user is that the sett<strong>in</strong>g of Work<strong>in</strong>gP<strong>re</strong>cision<br />

is not touched <strong>in</strong> any way, which means that the user himself must choose a <strong>re</strong>asonable value<br />

(<strong>in</strong> particular one g<strong>re</strong>ater than the mach<strong>in</strong>e p<strong>re</strong>cision). The meta algorithm that is used is<br />

shown <strong>in</strong> g. 7.3. This algorithm is of course applied only if error control is enabled, otherwise<br />

the function works much like PartInt.<br />

compute <strong>in</strong>itial set of partition po<strong>in</strong>ts fx0;x1;::: ;xng<br />

compute rst partial <strong>in</strong>tegral R x0<br />

a f(x) dx<br />

compute partial <strong>in</strong>tegrals R xi+1<br />

f(x) dx<br />

xi<br />

compute sequence limit<br />

iterations := 1<br />

while not <strong>re</strong>ached p<strong>re</strong>cision or accuracy or maximum iterations do<br />

compute il additional partition po<strong>in</strong>ts<br />

compute additional partial <strong>in</strong>tegrals<br />

iterations := iterations + 1<br />

compute sequence limit<br />

check error conditions<br />

Figu<strong>re</strong> 7.3: The meta algorithm for OscIntControlled<br />

The portion of the function body that implements the control loop is given below. Note<br />

that the table of partition po<strong>in</strong>ts parttab is not augmented <strong>in</strong> each pass, but only the last<br />

element is kept befo<strong>re</strong> the new po<strong>in</strong>ts a<strong>re</strong> added. For the sake of simplicity, the variable ne<br />

that <strong>in</strong>itially holds the value of NSumExtraTerms is <strong>in</strong>c<strong>re</strong>ased by the number il of additional<br />

sequence members di<strong>re</strong>ctly.<br />

172

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

Saved successfully!

Ooh no, something went wrong!