From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Nonlinear Fitting

cancel
Showing results for 
Search instead for 
Did you mean: 

Analytical Partial Derivatives

The VI model for nonlinear fitting allows the calculation of partial derivatives, eliminating the built-in substitution of numerical derivatives that occurs if the derivatives are not provided. Often is it not worth to calculate the partial derivatives in the model, due to the additional complexity and possibilities of mistakes. In rare cases, analytical partial derivatives can give a slight advantage in accuracy and speed.

The documentation on this is a little sparse and all we really know is that the output is a 2D array.

So let's clear up the mistery and explain how the data in the 2D array needs to be arranged.

The partial derivatives output f'(X,a) is a 2D array with one column per fitting parameter and one row for each datapoint in the model function.

This means that you get the correct arrangement if the function and partial derivatives are calculated point-by-point in a FOR loop (old way). However, if you operate directly on the X array without the need for a FOR loop (typical way), the resulting 2D array needs to be transposed.

here is an image of the two possibilities:

ModelDerivatives.png

Note that the loop-free version is often more efficient due to better use of SSE instructions and it typically results in cleaner code.

0 Kudos
Message 1 of 1
(5,916 Views)