This is the mail archive of the gsl-discuss@sources.redhat.com mailing list for the GSL project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Nonlinear Least-Squares Fitting Help


Fleur, you do have a good point about the paramters.

Here is a better explination of my task.

The DE I solved was
d^2y/dx^2 - y*omega^2 = 0
split it into real and imaginary parts yeilds
d^2y_r/dx^2 - y_r*omega^2 = 0
d^2y_i/dx^2 - y_i*omega^2 = 0
which I solved successfully with the GSL

The thing is that the equation that I want to fit the generated plots to is

y = A*e^ikx + B*e^-ikx
where A, B are complex
so A = Ar + i*Ai  and B = Br + i*Bi

this was converted to
y = [ (Ar + Br)*cos(k*x) + (Bi - Ai)*sin(k*x) ] + i [ (Ai + Bi)*cos(k*x) + (Ar - Br)*sin(k*x) ]
y = y_r + i*y_i

The 2nd column from the data file corresponds to y_r so I used that in my fitting function.  So when I did what you suggested it did fix some things but I lost the ability to solve for the components of A, B which is what I have been charged to do.

I just finished my first year Physics so please forgive me if I'm giving too much or too little info.  I have been looking at the same problem for too long so if you or anyone could suggest a more appropriate course of action that'd be great as I can't think of another one.  I do believe that I am being restricted to the GSL though.  Not that I mind, it looks like a great library!

-- 
If you truly love the memory, you must set it free()!


On Wed, Jun 12, 2002 at 09:11:00PM +0200, Fleur Kelpin wrote:
> Hi, I am not sure if I understand you correctly but it seems to me that
> in fact y = (Ar + Br)*cos(k*x) +(Bi - Ai)*sin(k*x). In this case the
> parameters cannot be identified. Add one to Ar and subtract one from Br
> and the fit is the same.
> 
> So you had better estimate compound parameters Ar+Br, Bi-Ai and k.
> 
> On Wed, 12 Jun 2002, Reid Nichol wrote:
> 
> > I have solved a differential equation with the gsl successfully and now am attempting to fit the plots back to the function to extract the constants used in solving the DE.  As far as I can tell I have done everything to the specs required by the library.  But, the numbers I get back are nonsense (except k) and it quits after attempting the first iteration.
> >
> > The code is attached along with the input data.  Details follow.
> >
> >
> >
> > The function I have is
> > y = Ar*cos(k*x) - Ai*sin(k*x) + Br*cos(k*x) + Bi*sin(k*x)
> >
> > which would mean that my fitting function is
> > y = (Ar*cos(k*x) - Ai*sin(k*x) + Br*cos(k*x) + Bi*sin(k*x) - y_i)/sigma_i
> >
> > I am triing to solve for Ar, Ai, Br, Bi and k, so my Jacobian would be made up of
> > dy/dAr = cos(k*x)/sigma_i
> > dy/dAi = -sin(k*x)/sigma_i
> > dy/dBr = cos(k*x)/sigma_i
> > dy/dBi = sin(k*x)/sigma_i
> > dy/dk  = (-x*Ar*sin(k*x) - x*Ai*cos(k*x) - x*Br*sin(k*x) + x*Bi*cos(k*x))/sigma_i
> >
> > I get the numbers from x_init but with a +/- on the order of 10^34 except for k which comes out fine.
> >
> >
> > I have checked my math multiple times and found no mistakes and I can't find an error in my code although it is obvious that one exists.  I have spent alot of time on this and would appreciate any help!
> >
> > --
> > If you truly love the memory, you must set it free()!
> >
> 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]