Matlab fitting data to a function, where the function is a summation and periodic, syntax -
i attempting fit temperature data on last 50 years using lsqcurvefit, concerned fitting function has bad syntax.
the fitting function of form:
∑(ai+bi*t+ci*t^2)*(cos(vt+p))
summing i=1 n. t correspond time vector called time. ideally fitting should return values a, b, c, v, , p describe temperature data
i attempting fit daily maximum temperatures, vector called tmax.
so far have:
lsqcurvefit(fitfn(1,2,time),5,time,tmax)
where fitfn defined in script as
function f = fitfn(i,n,t) f=0; i=1:n f =@(i,n,a,b,c,v,p,t) f + (a+b*t+c*t^2)*(cos(v*t+p)); end
however whenever run lsqcurvefit error
error using fitfn>@(i,n,a,b,c,v,p,t)f+(a+b*t+c*t^2)*(cos(v*t+p)) (line 4) not enough input arguments. error in lsqcurvefit (line 199) initvals.f = feval(funfcn_x_xdata{3},xcurrent,xdata,varargin{:}); caused by: failure in initial user-supplied objective function evaluation. lsqcurvefit cannot continue.
i sure i'm making simple error i'm @ loss. i'm new matlab , don't quite understand how use anonymous functions. appreciated.
thanks reading
your fitfn wrong. think want:
f = @(x,t) (x(1)+x(2)*t+x(3)*t.^2)*cos(x(4)*t+x(5)) lsqcurvefit(f,zeros(1,5),time,tmax)
Comments
Post a Comment