forum.alglib.net
http://forum.alglib.net/

Curve fitting again?
http://forum.alglib.net/viewtopic.php?f=2&t=570
Page 1 of 1

Author:  slap [ Tue Apr 24, 2012 8:59 pm ]
Post subject:  Curve fitting again?

Hi,

The code extract below is from the vb.net example for the lsfit routines called "
Quote:
lsfit_d_nlf example
"


Code:
Dim x(,) As Double = New Double(,){{-1},{-0.8},{-0.6},{-0.4},{-0.2},{0},{0.2},{0.4},{0.6},{0.8},{1.0}}
        Dim y() As Double = New Double(){0.223130,0.382893,0.582748,0.786628,0.941765,1.000000,0.941765,0.786628,0.582748,0.382893,0.223130}
        Dim c() As Double = New Double(){0.3}
        Dim epsf As Double = 0
        Dim epsx As Double = 0.000001
        Dim maxits As Integer = 0
        Dim info As Integer
        Dim state As lsfitstate = New XAlglib.lsfitstate() ' initializer can be dropped, but compiler will issue warning
        Dim rep As lsfitreport = New XAlglib.lsfitreport() ' initializer can be dropped, but compiler will issue warning
        Dim diffstep As Double = 0.0001

        '
        '  Fitting without weights
        '
        xalglib.lsfitcreatef(x, y, c, diffstep, state)
        xalglib.lsfitsetcond(state, epsf, epsx, maxits)
        xalglib.lsfitfit(state, AddressOf function_cx_1_func, Nothing, Nothing)
        xalglib.lsfitresults(state, info, c, rep)
        System.Console.WriteLine("{0}", info) ' EXPECTED: 2
        System.Console.WriteLine("{0}", alglib.ap.format(c,1)) ' EXPECTED: [1.5]


I wish to try to use lsfit for curve fitting, but I'm not sure how the sort of problem I have should be set out in relation to various lsfit routines.

I understand that I must first create a solver object using one of the constructor functions - e.g xalglib.lsfitcreatef(x, y, c, diffstep, state)
in above code.

But I need help to establish how I should set up such a contructor? for the type of curve fitting problem I wish to code.

To give an example I have attached a file showing data for a measured curve, and a calculated curve composed of a weighted sum of four individual curves.

The first image and data show the calculated curve when the 4 coefficients are set to 1.

And the second image show it after solving by adjusting the coeffiients to get the best fit between the measured curve and the calculated curve.

I can se how x values are entered in the lsfit contructor, but I'm unsure how I should set it up to enter y values?

Any pointers and advice would be much appreaciated as I'd like to break away from having to do this in Excel.

many thanks

Attachments:
Binder2.pdf [53.51 KiB]
Downloaded 637 times

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/