MATLAB: Parameter fit differential equation to dataset

differential equationfitparameter

Hello!
I am trying to fit a differential equation to a dataset by adjusting the equation's parameters (c(1) and c(2)). My datasets consist of an evolution of sealevel (s) over time (t) and temperature (temp) over time. The equation is as follows:
ds/ dt=-(1-c(1))*c(2).*(tempi(t))
My code is not working and was hoping someone could please give me some pointers.
CODE:
function bestc = odeparamAsmb5()
%Initial data
load rcp85_antsmbmidmatlab.txt;
load rcp85_temperaturemidmatlab.txt;
time= rcp85_temperaturemidmatlab(:,1)-2006+1;%modifying the vector from [2006 2100] to [1 95] to match "i"
temp= rcp85_temperaturemidmatlab(:,2)+0.8;
sealevel=rcp85_antsmbmidmatlab(:,2);
plot(time,sealevel)
%information
tempi=@(t) interp1(time,temp,t);
f=@(c,t)-(1-c(1))*c(2).*(tempi(t));
simsealevel= zeros(1,95);
for t=1:1:95
simsealevel(t)= integral(f,t,t+1);
hold on
plot(time,simsealevel, '-r')
end
% Optimise difference between simsealevel and sealevel
fun= @(c,t)-(1-c(1))*c(2).*(tempi(t))- sealevel;
c0= [0.25,0.15];
lb= [0.25;0.15];
ub= [0.25;0.35];
x = lsqnonlin(fun,c0,lb,ub);
ERRORS:
Not enough input arguments.
Error in odeparamAsmb5>@(c,t)-(1-c(1))*c(2).*(tempi(t)) (line 14)
f=@(c,t)-(1-c(1))*c(2).*(tempi(t));
Error in integralCalc/iterateScalarValued (line 314)
fx = FUN(t);
Error in integralCalc/vadapt (line 132)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 75)
[q,errbnd] = vadapt(@AtoBInvTransform,interval);
Error in integral (line 88)
Q = integralCalc(fun,a,b,opstruct);
Error in odeparamAsmb5 (line 20)
simsealevel(t)= integral(f,t,t+1);

Best Answer

I have discussed this several times over the years. See for example Monod kinetics and curve fitting and Parameter Estimation for a System Of Differential Equations. I will be glad to help you, however I will need your data.
I suggest that you do not interpolate your data. The reason is that it creates data points that may not actually exist, since you have no idea what your data are doing except at the times and values you measured them.