# forum.alglib.net

ALGLIB forum
 It is currently Fri Sep 13, 2024 11:20 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.

 Page 1 of 1 [ 1 post ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Newbie Function QuestionPosted: Sat Feb 19, 2011 6:05 pm

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.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.lsfitresults(state, info, c, rep)
System.Console.WriteLine("{0}", info) ' EXPECTED: 2
System.Console.WriteLine("{0}", alglib.ap.format(c, 1)) ' EXPECTED: [1.5]
Environment.Exit(0)

Any help would be greatly appreciated.

Thank you!!
Nick Spencer

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 1 post ]

 All times are UTC

#### Who is online

Users browsing this forum: No registered users and 32 guests

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

Search for: