forum.alglib.nethttp://forum.alglib.net/ Newbie Function Questionhttp://forum.alglib.net/viewtopic.php?f=2&t=304 Page 1 of 1

 Author: GTE946e [ Sat Feb 19, 2011 6:05 pm ] Post subject: Newbie Function Question 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 SubPublic 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

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