0

I am trying to fit in matlab a temperature time series that follows this kind of functionenter image description here

I would need to retrieve the 8 parameters of the function, putting as boundary lambda=0 and sigma positive. I tried using the lsqcurvefit function in matlab, but I cannot use the y function inside this built in matlab funtion if I have a for loop in place.

Torontoless=xlsread('temp.xlsx',2);
xdata=zeros(1,6576);
x=[0,0,0,0,0,0];
ydata=Torontoless';
Toronto=[zeros(size(ydata,1),1) ydata];
fun=zeros(1,6576);
for i=1:6576
fun(i)=(1-x(1))*(Toronto(i)-(x(2)+x(3)*Toronto(i)+x(4)*(sin(x(5)*Toronto(i)+x(6)))))+x(2)+x(3)*Toronto(i+1)+x(4)*(sin(x(5)*Toronto(i+1)+x(6)))+(randn-x(7))*x(8);
end

x0=[0,0,0,0,0,0];
lb=[-1000,-1000,-1000,-1000,-1000,-1000,0,0];
ub=[1000,1000,1000,1000,1000,1000,0,1000];

Now, I don't know how to use the fun inside the function x=lsqcurvefit(fun,x0,xdata,ydata,lb,ub)

I don't know if there is a better way to fit this kind of time series, but let me know if you have something in mind to solve the problem. Thanks a lot.

PS The size of the temp vector is 1x6576. As I wanted temperature to start at 0, I added an extra column at first.

Alessandro
  • 43
  • 1
  • 4
  • The problem looks a bit weird to me, the new temperature depends on the temperature on the previous time step? `j` is a discrete time variable? Could you explain a bit more about your data? – rinkert Nov 27 '18 at 15:11
  • yes, sorry that j-1 and j in the second line of the figure is a T_{j-1} and T_{j}, so the temperature today depend on yesterday too. – Alessandro Nov 27 '18 at 15:18
  • I see only 5 parameters. *(ε λ).σ* is some noise term. You need to express the measured temperatures *T_j* as a function of α and model temperatures *Tm_j* and *Tm_(j-1)*. *C.sin(ωj+Φ)* can be expressed as *D.sin(ωj)+E.cos(ωj)*. For a given α, seeking a best fit for A,B,D&E is a simple linear optimization problem. Then seeking the value of α that gives the best fit is a 1D optimization problem. – Brice Nov 27 '18 at 15:28

0 Answers0