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

Home » Public Forums » archive » Re: Least Square
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
Re: Least Square [message #9714] Fri, 08 August 1997 00:00
John Lawrence is currently offline  John Lawrence
Messages: 1
Registered: August 1997
Junior Member
R.J. Hall wrote:
+> I was windering if the following can be solced using IDL (V4)

+> Is it possible to find the line of best fit, and thus derive its
=>equation using IDL?
=>
+> The form of the equation is as follows:-
+> y = a * sin (b*x + c)

If you do the algebra on paper, IDL can do the arithmetic.
It is a large number of summations, and then a matrix inversion.
Actually, I used to do it in Excel. IDL is heaps easier.


- ;-} --- :-{ --- ;-} --- :-{ --- ;-} -
The fundamental particle of stupidity is called the Bozon.
Re: Least Square [message #9717 is a reply to message #9714] Thu, 07 August 1997 00:00 Go to previous message
J.D. Smith is currently offline  J.D. Smith
Messages: 214
Registered: August 1996
Senior Member
R.J. Hall wrote:
>
> Dear all,
>
> I was windering if the following can be solced using IDL (V4)
>
> Data:- Change in voltage against time
>
> Result:- Sinusoidal wave
>
> Is it possible to find the line of best fit, and thus derive its
> equation using IDL?
>
> The form of the equation is as follows:-
>
> y = a * sin (b*x + c)
>
> Many thanks in advance
>
> Richard

You can use curvefit() as follows

Result = CURVEFIT(time, voltage, Weights, A, FUNCTION_NAME='sinfunc')

Weights can be replicate(1.0,n_elements(time)) if there is no
weighting.
A is a vector of your parameters ... A=[a,b,c], set to an initial guess.
and sinfunc must be a function as follows:

function sinfunc,time, A, funcval, pder
s=sin(A[1]*time+A[2])
funcval=A[0]*s
IF N_PARAMS() GE 4 THEN BEGIN
cfac=funcval*cos(A[1]*time+A[2])
pder=[s,time*cfac, cfac]
ENDIF
end
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Share memory between C and IDL-RPC-server?
Next Topic: Re: delete a tagname from a structure?

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

Current Time: Wed Oct 08 13:46:23 PDT 2025

Total time taken to generate the page: 0.00561 seconds