Re: Least Square [message #9714] |
Fri, 08 August 1997 00:00 |
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  |
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
|
|
|