Here is example for VBA:
Code:
'Routines
Public Sub DemoRoutine()
Dim State As MinLMState
Dim Rep As MinLMReport
Dim S() As Double
Dim X As Double
Dim Y As Double
'
' Example of solving simple task using FJ scheme.
'
' Function minimized:
' F = (x-2*y)^2 + (x-2)^2 + (y-1)^2
' exact solution is (2,1).
'
ReDim S(0 To 2#-1)
S(0#) = Rnd()-0.5
S(1#) = Rnd()-0.5
Call MinLMCreateFJ(2#, 3#, S, State)
Call MinLMSetCond(State, 0.0, 0.0, 0.001, 0#)
Do While MinLMIteration(State)
X = State.X(0#)
Y = State.X(1#)
If State.NeedF then
State.F = Square(X-2#*Y)+Square(X-2#)+Square(Y-1#)
End If
If State.NeedFiJ then
State.Fi(0#) = X-2#*Y
State.Fi(1#) = X-2#
State.Fi(2#) = Y-1#
State.J(0#,0#) = 1#
State.J(0#,1#) = -2#
State.J(1#,0#) = 1#
State.J(1#,1#) = 0#
State.J(2#,0#) = 0#
State.J(2#,1#) = 1#
End If
Loop
Call MinLMResults(State, S, Rep)
'
' output results
'
ConsoleOutputString "X = " & FormatFReal(S(0#), 4, 2) _
& " (correct value - 2.00)" & vbNewLine
ConsoleOutputString "Y = " & FormatFReal(S(1#), 4, 2) _
& " (correct value - 1.00)" & vbNewLine
ConsoleOutputString "TerminationType = " & FormatInteger(Rep.TerminationType, 0) _
& " (should be 2 - stopping when step is small enough)" _
& vbNewLine
ConsoleOutputString "NFunc = " & FormatInteger(Rep.NFunc, 0) _
& vbNewLine
ConsoleOutputString "NJac = " & FormatInteger(Rep.NJac, 0) _
& vbNewLine
ConsoleOutputString "NGrad = " & FormatInteger(Rep.NGrad, 0) _
& vbNewLine
ConsoleOutputString "NHess = " & FormatInteger(Rep.NHess, 0) _
& vbNewLine
End Sub
I also recommend to read
viewtopic.php?f=2&t=61&start=0 It discusses slightly different optimizer, but with similar interface.