This class contains code to perform fitting of function parameters using inputs of dependent and observed variables. It is translated from Fortran version of MINPACK.
Following is example usage of this class:
Dim levObj As New Levenberg
res = levObj.CalibrateParameters("MyFunction", x, y, p)
where
x : a vector of independent variables
y : observed values
p: vector of initial guess values for parameters
MyFunction : name of VBA function which implements the fucntion f(x,p)
res : output vector of calibrated parameter values
eg., for a function f(x)=ax^2+bx+c:
Public Function MyFunction(params As Variant, x As Variant) As Variant
a = params(1)
b = params(2)
c = params(3)
m = UBound(x)
ReDim function_values(1 To m)
For i = 1 To m
xi = x(i)
function_values(i) = a * xi * xi + b * xi + c
Next i
MyFunction = function_values
End Function
To check out an actual demo for usage, refer to
Parameters calibration demo for Levenberg Marquardt algorithm