[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-gsl] Non-linear Multi-parameter Least-Squares Example
From: |
Gordan Bobic |
Subject: |
[Help-gsl] Non-linear Multi-parameter Least-Squares Example |
Date: |
Tue, 17 Jul 2007 12:46:12 +0100 (BST) |
Hi,
I have a question regarding the example 37.9 in the manual.
In the df function, there is the following code:
for (i = 0; i < n; i++)
{
/* Jacobian matrix J(i,j) = dfi / dxj, */
/* where fi = (Yi - yi)/sigma[i], */
/* Yi = A * exp(-lambda * i) + b */
/* and the xj are the parameters (A,lambda,b) */
double t = i;
double s = sigma[i];
double e = exp(-lambda * t);
gsl_matrix_set (J, i, 0, e/s);
gsl_matrix_set (J, i, 1, -t * A * e/s);
gsl_matrix_set (J, i, 2, 1/s);
}
I am trying to adapt this to fit a generic sine curve. So, I am trying to
do something like this:
for (i = 0; i < n; i++)
{
/* Jacobian matrix J(i,j) = dfi / dxj, */
/* where fi = (Yi - yi)/sigma[i], */
/* Yi = a * sin(b / t + c) + d */
/* and the xj are the parameters (a,b,c,d) */
double t = i;
double s = sigma[i];
double e = sin(b / t + c);
gsl_matrix_set (J, i, 0, e/s);
gsl_matrix_set (J, i, 1, cos (b / t + c) * e/s);
gsl_matrix_set (J, i, 2, 1/s);
gsl_matrix_set (J, i, 3, 1/s);
}
Is this a correct adaptation, or am I misunderstanding what this is
supposed to do? Is the 4th parameter in this case the
differential/derivative of the Yi equation with respect to a, b, c and d
respectively?
Thanks.
Gordan