Finding parameters of a differential function by minimising the difference with dataset

1 次查看(过去 30 天)
Hello,
I am trying to find the optimal parameters that minimise the difference between my dataset and the equation that I am trying to fit.
My dataset consists of two yearly evolutions (2006- 2100) of temperature (T) and sea level (s) and the equation I am trying to fit is:
ds/ dt = - (1- c1)* c2 * T(t)
I don't have a mathematical representation for T(t), only the time series over the same time period as "s"'s evolution.
I have lower and upper boundaries for both constants c1 and c2 and need to find the best parameters to minimise the difference with the s(t).
My code is not working and was really hoping I might get some pointers as to how I can fix this.
Many thanks in advance!
CODE:
function bestc = odeparamAsmb3()
%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);
%Initial guess
c0= [0.25,0.15];
%fun=@(t)updateStates(t,z,c0,tempi);
for i=1:1:94
int= integral(f,i,i+1);
simsealevel = deval(int,time); % Evaluate the solution at the experimental time steps
hold on
plot(time, simsealevel, '-r')
%% Set up optimization
myObjective = @(x) objFcn(x,time,sealevel,tempi,i);
lb = [0.25,0.15];
ub = [0.25,0.35];
bestc = lsqnonlin(myObjective,c0, lb, ub);
%% Plot best result
for i=1:1:94
int= integral(fun,i,i+1);
bestsealevel = deval(int, time);
plot(time, bestsealevel, '-g')
legend('IPCC Data','Initial Param','Best Param');
function f = updateStates(t,c,tempi);
f=(-(1-c(1))*c(2).*tempi(t));
function cost= objFcn (x,time,sealevel,tempi,i)
for i=1:1:94
int= integral(f,i,i+1);
simsealevel = deval(int, time);
cost = simsealevel-sealevel;
ERROR:
Error: File: odeparamAsmb3.m Line: 49 Column: 1
Function definition is misplaced or improperly nested.

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Nonlinear Optimization 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by