4 Verification

Macri didn't describe any way of verifying the correctness of his derivations or implementation. Once I had initially implemented the simulator, I found bugs but had no way of determining where an error was occurring. To address this, I used numeric derivatives.

For example, suppose that we need to verify the calculation of $ \frac{\partial f(x)}{\partial x}
$ . Our program calculates the derivative using an analytic formula, which we'll call $ f'_a(x)$ . The derivative can also be calculated numerically:

$\displaystyle f'_n(x) = \frac{f(x+h)-f(x)}{h} $

If $ f'_a(x) = f'_n(x)$ , then the implementation and analytic formula give the correct results.

Verification is a little bit trickier for the bend condition. Here, we can't just use a normal derivative, since we have to differentiate under the assumption that the vectors have constant magnitude. Suppose that we want to verify the derivative $ \frac{\partial {\bf {\hat n}}^A}{\partial {\bf x}_{m_s}}
$ . Let $ {\bf n}^A({\bf x}_{m_s})$ represent the normal with point $ m$ at position $ {\bf x}_{m_s}$ , and $ {\bf n}^A({\bf x}_{m_s}+ h{\bf I}_s)$ represent the normal once point $ m$ 's $ s$ th component is shifted by $ h$ . The unit normals are then given by

$\displaystyle {\bf {\hat n}}^A({\bf x}_{m_s})$ $\displaystyle = \frac{{\bf n}^A({\bf x}_{m_s})}{\begin{Vmatrix}{\bf n}^A({\bf x}_{m_s})\end{Vmatrix}}$    
$\displaystyle {\bf {\hat n}}^A({\bf x}_{m_s}+ h{\bf I}_s)$ $\displaystyle = \frac{{\bf n}^A({\bf x}_{m_s}+ h{\bf I}_s)}{\begin{Vmatrix}{\bf n}^A({\bf x}_{m_s})\end{Vmatrix}}$    

And the numeric derivative is given by

$\displaystyle \left({{\bf {\hat n}}^{A}}_n\right)'$ $\displaystyle = \frac{{\bf {\hat n}}^A({\bf x}_{m_s}+ h{\bf I}_s) - {\bf {\hat n}}^A({\bf x}_{m_s})}{h}$    

The main trick is to normalise the shifted edge and normal vectors using the magnitude of the unshifted vector.

To be honest, I don't know why numeric derivatives can't be used for everything. I suspect that they may be less robust than analytic derivatives, and there may be a performance tradeoff involved, but I haven't confirmed these suspicions.