** ADO FILE:
Code:
/* User written command by Leah E. M. Bevis */
/* December 2018 */
/* Input: coefficients (a,b,c,d) from the terms of this 4-term Fourier series: */
/* y = k + a*cos(2*pi*t/T1) + b*sin(2*pi*t/T1) + c*cos(2*pi*t/T2) + d*cos(2*pi*t/T2) */
/* Output: maximum, minimum, amplitude, index of lowest point */
program sinusoid
version 14.2
args a b c d
mata: FourierAmp(`a',`b',`c',`d')
end
version 14.2
mata:
void FourierAmp(a, b, c, d) {
t = (1::365)
t=t/365
T1=1
omega1=2*pi()/T1
T2=1/2
omega2=2*pi()/T2
y=a*cos(omega1*t) + b*sin(omega1*t) + c*cos(omega2*t) + d*sin(omega2*t)
lowpoint=999
w=999
minindex(y,1,lowpoint,w)
minimum=min(y)
maximum=max(y)
amplitude=maximum-minimum
st_matrix("minimum", minimum)
st_matrix("maximum", maximum)
st_matrix("amplitude", amplitude)
st_matrix("lowpoint", lowpoint)
}
end
** CONTEXT FOR USE
Code:
reg Y csmnth snmnth csmnth2 snmnth2
local a = _b[csmnth]
local b = _b[snmnth]
local c = _b[csmnth2]
local d = _b[snmnth2]
sinusoid `a' `b' `c' `d'
mat lis amplitude
mat lis minimum
mat lis maximum
mat lis lowpoint
0 Response to Problem exporting matrix from mata ado
Post a Comment