comp.lang.idl-pvwave archive - RDF feed
type: channel
description: Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
items: Re: Least Square

Re: Least Square
type: item
description: 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
creator: J.D. Smith
date: 1997-08-07T07:00:00-00:00

Re: Least Square
type: item
description: 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.
creator: John Lawrence
date: 1997-08-08T07:00:00-00:00