The text-book trapezoidal rule (for unit time-step) is y[n+1] = y[n] + (1/2)*(x[n] + x[n+1]), where x[n+1] is what we solve using whatever method such as LU + Newton.Yeah I was thinking it would save an addition and division per sample but that's only in the naive implementation in my head, I am sure optimizing it removes that advantage. (It probably is trivial to optimize to just one division total for example.)
There's no division. In practice, there's also kinda not a multiplication either, because the 0.5 factor can simply be merged into the tuning (or conductance in the circuit simulation case) coefficients, that is, we solve for (1/2)*x[n+1] directly (eg. by using tan(pi*f/fs) as tuning rather than 2*tan(pi*f/fs) which would be the text-book coefficient before averaging).
Finally, in the fixed time-step case we can write the integrator in "transposed direct form 2" form eliminating the second state variable that we'd need for x[n] in the text-book (= direct form 1) version:
y[n+1] = s[n] + (1/2)*x[n+1]
s[n+1] = y[n+1] + (1/2)*x[n+1]
That is, we add the contribution of (1/2)*x[n+1] that will be the (1/2)*x[n] term for the next time step already into the state variable as we update it.
The linear system we solve can also be written in terms of s[n] rather than y[n] so only s[n] needs to be preserved to the next time-step, so the most you will lose is perhaps one add per dimension... and that's assuming we won't need any extra multiplications to solve for a half time-step in the midpoint case (no idea if that can be optimized out; either way, the difference isn't exactly huge one way or another).
ps. In a sense we're solving for both at the same time: y[n] is the trapezoidal and s[n] is the mid-point shifted half time-step.
Statistics: Posted by mystran — Tue Aug 20, 2024 9:13 pm