forum.alglib.net

ALGLIB forum
It is currently Sun Oct 13, 2024 7:01 am

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: Newbie Function Question
PostPosted: Sat Feb 19, 2011 6:05 pm 
Offline

Joined: Sat Feb 19, 2011 5:40 pm
Posts: 1
I'm trying to fit the following equation:


Function f(x) = A-2*sqr(A*B) *(1-A)*e^(-CX) *COS(Dx-E)


Can anyone help me turn this into a function I can use for fitting for this?

I'm using VB.net and am trying to use the following code as a basis;
Public Sub function_cx_1_func(ByVal c As Double(), ByVal x As Double(), ByRef func As Double, ByVal obj As Object)
'
' this callback calculates f(c,x)=exp(-c0*sqr(x0))
' where x is a position on X-axis and c is adjustable parameter
'
func = System.Math.Exp(-c(0) * x(0) * x(0))
End Sub

Public Sub Test
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.22313, 0.382893, 0.582748, 0.786628, 0.941765, 1.0, 0.941765, 0.786628, 0.582748, 0.382893, 0.22313}
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]

'
' Fitting with weights
' (you can change weights and see how it changes result)
'
Dim w() As Double = New Double() {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
XAlglib.lsfitcreatewf(x, y, w, 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]
System.Console.ReadLine()
Environment.Exit(0)


Any help would be greatly appreciated.

Thank you!!
Nick Spencer


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 3 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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group