comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Help with least squares on non-linear function
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Help with least squares on non-linear function [message #85657] Sat, 24 August 2013 12:14 Go to next message
stefan.meingast is currently offline  stefan.meingast
Messages: 30
Registered: June 2012
Member
Hey

I finally want to enjoy at least some time of the weekend, but I am stuck at one problem tonight for which I still would like to find a solution.

I have a bunch of measurements in an array y which depending basically on another variable x. I want to do a least-squares fit to a non-linear function, which would be very easy if I just wanted e.g. a polynomial fit. My problem is now that there is another parameter coming into play (here: k), so the function I want to fit in the end looks like this (though the order should be variable in the end which in this example is set to 3):

https://dl.dropboxusercontent.com/u/16787607/formula.jpg

where the a_i are the coefficients I want to determine.

I have been trying to figure out what the best way might be to do such a fit, but this turns out to be much more complicated than I thought...

I hope some of you may have a hint

many thanks!!!
:)
Re: Help with least squares on non-linear function [message #85658 is a reply to message #85657] Sat, 24 August 2013 12:20 Go to previous messageGo to next message
stefan.meingast is currently offline  stefan.meingast
Messages: 30
Registered: June 2012
Member
Ah, one more thing:

The k changes for each y so it is not constant across all measurements...
Re: Help with least squares on non-linear function [message #85659 is a reply to message #85658] Sat, 24 August 2013 14:10 Go to previous messageGo to next message
Phillip Bitzer is currently offline  Phillip Bitzer
Messages: 223
Registered: June 2006
Senior Member
Is k known a priori? In other words, do you know what k is for each measurement?
Re: Help with least squares on non-linear function [message #85660 is a reply to message #85659] Sat, 24 August 2013 14:32 Go to previous messageGo to next message
stefan.meingast is currently offline  stefan.meingast
Messages: 30
Registered: June 2012
Member
Am Samstag, 24. August 2013 23:10:45 UTC+2 schrieb Phillip Bitzer:
> Is k known a priori? In other words, do you know what k is for each measurement?

Yes, I know k. Actually, I just realised that k is equal to 1/X, so this makes things a lot easier. I am currently experiemnting with MPFIT where you can define any function you want to fit. This looks very promising so far.
Re: Help with least squares on non-linear function [message #85661 is a reply to message #85660] Sat, 24 August 2013 14:53 Go to previous messageGo to next message
Phillip Bitzer is currently offline  Phillip Bitzer
Messages: 223
Registered: June 2006
Senior Member
Yep, that was the next piece of advice :-) MPFIT is highly recommended....
Re: Help with least squares on non-linear function [message #85664 is a reply to message #85661] Sun, 25 August 2013 05:40 Go to previous message
Heinz Stege is currently offline  Heinz Stege
Messages: 189
Registered: January 2003
Senior Member
On Sat, 24 Aug 2013 14:53:39 -0700 (PDT), Phillip Bitzer wrote:

> Yep, that was the next piece of advice :-) MPFIT is highly recommended....

I would say, this is a linear function. Here is a way how to calculate
the fit parameters.

Put your x, k and y values into the arrays
x=dblarr(npoints)
k=dblarr(npoints)
y=dblarr(npoints)

With npars=3, create the matrix
fx=dblarr(npoints,npars)
for i=1,npars do fx[0,i-1]=((1+k)^i-k^i)*x^i

and do the calculation
temp=transpose(fx)
a=temp#fx
b=temp#y
ludc,a,indx
par=lusol(a,indx,b)

par is an array with npars elements and should contain the fit
parameters named by a_i within your function.

I hope, that there is no error in this code. I couldn't test it,
because I have no example values for x, k and y.

Cheers, Heinz
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: FONT_SIZE in PLOT()
Next Topic: Does Java polymorphism not work via the IDL Java Bridge?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:14:11 PDT 2025

Total time taken to generate the page: 0.00774 seconds