Platforms to show: All Mac Windows Linux Cross-Platform

/Tools/lmfit/curve


Required plugins for this example: MBS Tools Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Tools/lmfit/curve

This example is the version from Sat, 15th Nov 2019.

Project "curve.xojo_binary_project"
Class App Inherits ConsoleApplication
EventHandler Function Run(args() as String) As Integer dim c as new curve1 c.test End EventHandler
End Class
Class Curve1 Inherits LMFitMBS
EventHandler Function evaluateCurve(t as double, par as Ptr, nPar as Integer, parameters() as double, tag as variant) As double Return f(t, par) End EventHandler
Shared Function f(t as double, par() as Double) As Double dim p0 as double = par(0) dim p1 as double = par(1) dim p2 as double = par(2) return p0 + p1*t + p2*t*t End Function
Shared Function f(t as double, par as ptr) As Double dim p0 as double = par.Double( 0) dim p1 as double = par.Double( 8) dim p2 as double = par.Double(16) return p0 + p1*t + p2*t*t End Function
Sub test() const n = 3 // number of parameters in model function f */ dim par() as double = Array( 100.0, 0, -10) // really bad starting value */ // data points: a slightly distorted standard parabola */ const m = 9 dim t() as double = Array( -4., -3., -2., -1., 0., 1., 2., 3., 4. ) dim y() as double = Array( 16.6, 9.9, 4.4, 1.1, 0., 1.1, 4.2, 9.3, 16.4 ) Dim control As New LMFitControlMBS dim status as new LMFitStatusMBS control.verbosity = 9 print "Fitting ..." // now the call to lmfit */ me.LMCurve( n, par, m, t, y, control, status ) print "Results:" print "status after %d function evaluations: "+status.outcomeInfoMessage print "obtained parameters:" for i as integer = 0 to n-1 print " par("+str(i)+") = " + str(par(i)) next print "obtained norm: "+ str(status.fnorm ) print "fitting data as follows:" for i as integer = 0 to m-1 dim r as Double = f(t(i), par) print " t["+str(i,"00")+"]="+str(t(i))+" y="+str(y(i))+" fit="+str(r)+" residue="+str(y(i) - r) next End Sub
End Class
End Project

The items on this page are in the following plugins: MBS Tools Plugin.


The biggest plugin in space...