An observation about computing the Simpson’s Sum, as a numerical approximation of an Integral.

One of the subjects which I posted about before, is the fact that in practical computing, often there is an advantage to using numerical approximations, over trying to compute Algebraically exact solutions. And one place where this happens, is with integrals. The advantage can be somewhere, between achieving greater simplicity, and making a solution possible. Therefore, in Undergraduate Education, emphasis is placed in Calculus 2 courses already, on not just computing certain integrals Algebraically, but also, on understanding which numerical approximations will give good results.

One numerical approximation that ‘gives good results’, is The so-called Simpson’s Sum. What it does, is to perform a weighted summation of the most-recent 3 data-points, into an accumulated result. And the version of it which I was taught, sought to place a weight of 2/3 on the Midpoint, as well as to place a weight of 1/3 on the Trap Sum.

In general, the direction in which the Midpoint is inaccurate, will be opposite to the direction in which the Trap Sum is inaccurate. I.e., if the curve is concave-up, then the Midpoint will tend to underestimate the area under it, while the Trap Sum will tend to overestimate. And in general, with integration, consistent under- or over-estimation, is more problematic, than random under- or over-estimation would be.

But casual inspection of the link above will reveal, that this is not the only way to weight the three data-points. In effect, it’s also possible to place a weight of 1/2 on the Midpoint, plus a weight of 1/2 on the Trap Sum.

And so a logical question to ask would be, ‘Which method of summation is best?’

The answer has to do, mainly, with whether the stream of data-points is ‘critically sampled’ or not. When I was taking ‘Cal 2′, the Professor drew curves, which were gradual, and the frequencies of which, if the data-points did form a stream, would have been below half the Nyquist Frequency. With those curves, the Midpoint was visibly more-accurate, than the Trap Function.

But one parameter for how Electrical Engineers have been designing circuits more recently, not only states that an analog signal is to be sampled in the time domain, but that the stream of samples which results will be critically sampled. This means considerable signal-energy, all the way up to the Nyquist Frequency. What will result is effectively, that all 3 data-points will be as if random, with great variance between even those 3.

Under those conditions, there is a slight advantage to computing the average, between the Midpoint, and the Trap Sum.

(Update 12/08/2018, 20h25 : )

I’ve just prepared a small ‘wxMaxima’ work-sheet, to demonstrate the accuracy of the 2/3 + 1/3 method, applied to a sine-wave at 1/2 Nyquist Frequency:

Worksheet

(Update 12/09/2018, 12h35 : )

Continue reading An observation about computing the Simpson’s Sum, as a numerical approximation of an Integral.

Why the Simpson’s Sum Does Not Get Used In Circuit Simulations

In recent postings I have been sharing my experiences, learning to use the software ‘NG-SPICE’, which uses numerical methods to simulate circuit-diagrams. Well, to simulate ‘Netlists’ anyway, that represent circuits. And the GUI which I have has as drawback, not being as fancy as some commercial GUIs, and only allowing me to perform certain types of simulations, that include DC Sweeps, AC Sweeps, and Pulses. I think that if I was to delve deeper, and edit my Netlists using a text-editor, I might be able to expand the range of possibilities…

But then I do think that a premise of how ‘SPICE’ works in general, is to state the Voltage as a Primary phenomenon, to which Current is Secondary. By that I mean, pure capacitors are simulated as having current, that is the derivative of voltage, while in pure inductors, the current is merely the integral of voltage. ( :2 ) And so, SPICE uses numerical approximations of both derivatives and integrals. ( :1 ) And in the many settings my GUI does offer me, I get to choose which method of integration out of two I prefer: ‘Trap’ or ‘Gear’.

The question could just pop into somebody’s head: ‘Methods of numerical integration were taught to me, which are more accurate than Trap, such as The 3-point Simpson’s Sum. (Actually, I was taught to compute 2/3 times the Midpoint, plus 1/3 times the Trap Sum, not their average.) Why can’t I select that?’ And the answer I would suggest is as follows: I already wrote a posting about the simplest method of numerical differentiation, and about how, if the step-size is too long, it can generate differentials which are too high in amplitude. If this was combined with an unsuitable method of integration, one of two paradoxical results could follow:

  1. An LC tank circuit, aka a pure inductor connected to a pure capacitor, could end up unstable, gaining amplitude, or
  2. The same, simulated circuit could lose momentum, apparently to nowhere, and stop ringing.

Either result is counter to what happens in Physics. And so it would seem that the medium-range errors in the Trap method, happen to complement the errors exactly, in the simplest method of differentiation. If the differentiation came into being because consecutive samples were subtracted, then simply to add them again, will reproduce what we started with. And so our pure, lossless resonant circuit, would resonate forever, as it should… The engine has no place for ‘dampened integrals’ here.

The other method available, ‘Gear’, is also known as ‘The Backward Differentiation Formula’, or the ‘BDF’. It’s mainly suited for trying to simulate systems which are ‘stiff’ i.e., where the step-interval is assumed to be too long, and where heavy bodies interact with great force, approximated with coarse time-steps. It’s like The Simpson’s Sum on steroids. I’ve heard bad things about it. One main reason not to use it, is the History by which it will stabilize a simulated circuit, while the same circuit, when actually etched into silicon, became unstable. There might be cases where only the Gear Method can be used, but it should be used as a last resort.

The (simpler) ‘Riemann Sum’ has as a problem, that it must either be conceptualized as being ‘left-handed’ or ‘right-handed’, which means, that each input sample must either represent an abstract rectangle that follows it, or that preceded it. With critically-sampled – i.e., long stepped – signals, doing so would introduce a phase-shift. The Trap Sum alleviates such a phase-shift.

(Updated 06/23/2018, 19h35 … )

Continue reading Why the Simpson’s Sum Does Not Get Used In Circuit Simulations