forum.alglib.net

ALGLIB forum
It is currently Sat Jul 02, 2022 5:50 pm

All times are UTC


Forum rules


1. This forum can be used for discussion of both ALGLIB-related and general numerical analysis questions
2. This forum is English-only - postings in other languages will be removed.



Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Curve fitting again?
PostPosted: Tue Apr 24, 2012 8:59 pm 
Offline

Joined: Mon Apr 16, 2012 12:24 pm
Posts: 5
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 400 times
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group