trigonemetric function fitting using matrice in matlab

hi
please explain me these line of codes from the matlab documentation:
Simulating Electricity Prices with Mean-Reversion and Jump-Diffusion
why do we have to put t in matrice function when we have f(t)= s1*sin(2.pi.t)+s2*cos(2.pi.t)+s3*sin(4.pi.t)+s4*cos(4.pi.t)+s5 ?
% Calibrate parameters for the seasonality model
seasonMatrix = @(t) [sin(2.*pi.*t) cos(2.*pi.*t) sin(4.*pi.*t) ...
cos(4.*pi.*t) t ones(size(t, 1), 1)];
C = seasonMatrix(PriceTimes);
seasonParam = C\logPrices;

3 个评论

Your equation is
f(t)= s1*sin(2.pi.t)+s2*cos(2.pi.t)+s3*sin(4.pi.t)+s4*cos(4.pi.t)+s5 ?
You have 5 uknowns s1 - s5
To calculate them you need 5 equations:
Where a1,b1,c1,d1,e1 == [cos(2.*pi.*t) sin(4.*pi.*t) cos(4.*pi.*t) 1];
Thanks for your reply, I was expecting the same matrice, but in the help documentation of the problem resolution Matlab add the sixth variable t, thing that I didnot understand.
kindly find Simulating Electricity Prices with Mean-Reversion and Jump-Diffusion in help documentation to look at the code deeply.

请先登录,再进行评论。

回答(1 个)

ok thanks
what about this line of code
seasonParam = C\logPrices;
I used inv(X'X)X'Y to find the parameters of the fitting function. can you please explain me what they mean?

4 个评论

let's consider f the function to fit with the set of data x={x1,x2, x3....xn} and y={y1, y2, y3.... yn} and f(x)=a0+bx
fiting f with (x1,y1), (x2, y2).....(xn,yn) lead to
f(x1)=a0+bx1=y1
f(x2)=a0+bx2=y2
f(xn)=a0+bxn=yn
hence, X*A=Y with A the parameter matrice of the function f and is find by A=inv(X'X)X'Y, with X' the transpose of X
A is just . No transposing needed
where X and Y for this case:
X = [1 x1
1 x2];
Y = [y1; y2]

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Energy Production 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by