JPhrases/SimpsonIntegraton/ExtremeTesting

From J Wiki
Jump to navigation Jump to search

Simpson Integration: How to Test it

This continues the testing done here but carried to extremes.

Our basic sanity test of integrating with the Simpson method was one that is very well-defined with a known answer of zero. However, there is a known "busy" function - (1 o. %) - which is the sine of the reciprocal of x as x approaches zero. This still ought to integrate to very close to zero as the function is still periodic with roughly equal positive and negative areas.

So we can define this busy function like this:

   Marge=: 1 o. %

This is what Marge looks like from 0.0001 to 0.001 for 10,000 points: Margebounds0.0001to0.001 1e4.png

How good is our Simpson integration over this same range? MargeSimpson000010011e4.png

That does not look too bad. We are off by very small amounts.

An Even Busier Function

Now let's look at an even busier "function":

   Bart=: ([: -/\ 1 o. %) * [: -/\ 2 o. %

BartBounds0001to01 1e4.png

Uh oh! Bart looks like a monster! Here is how well it integrates: BartSimpson0001to001 1e4.png

It's not bad for such a monster.