Fit an Ordinary Differential Equation (ODE) using fmincon

조회 수: 7 (최근 30일)
Jonas Hilpert
Jonas Hilpert 2018년 11월 19일
댓글: Jonas Hilpert 2018년 11월 19일
I have a system of 2 ODE's (ode45) and want to fit them to measured data. For that i have 4 variables i want to optimate.
This is my code:
% ode45
tspan=linspace(0,3785,3785);
ic=[300 300];
x=ones(1,4);
f = @(t,T) [(x(1)*(T(2)-T(1))+x(2))/100; x(3)*(T(1)-T(2))+x(4)*(300-T(2))];
[t,T]= ode45(f,tspan,ic);
% ydata from excel
filename='Messung_1.xlsx';
sheet =12;
Range1='C6:C3790';
Range2='D6:C3790';
t_Kl=xlsread(filename,sheet,Range1)+273.15;
t_Nl=xlsread(filename,sheet,Range2)+273.15;
ydata=[t_Kl t_Nl];
% objective function
objective= @(x) sum(((T(:,1)-ydata(:,1))./ydata(:,1)).^2)+sum(((T(:,2)-ydata(:,2))./ydata(:,2)).^2);
x0=ones(1,4);
pbest=fmincon(objective,x0);
When i try to solve this: Initial point is a local minimum that satisfies the constraints.
Can someone help me please?
  댓글 수: 2
Torsten
Torsten 2018년 11월 19일
편집: Torsten 2018년 11월 19일
Please show the complete code you are using - not only some snippets.
Your objective function as written does not depend on x. Thus it always returns the same value to "fmincon". This means that the initial point is a local minimum that satisfies the constraints.
Jonas Hilpert
Jonas Hilpert 2018년 11월 19일
allright i edited my question. How can i make my objective function to be depended on x?

댓글을 달려면 로그인하십시오.

채택된 답변

Torsten
Torsten 2018년 11월 19일
편집: Torsten 2018년 11월 19일
function main
% ydata from excel
filename = 'Messung_1.xlsx';
sheet = 12;
Range1 = 'C6:C3790';
Range2 = 'D6:C3790';
t_Kl = xlsread(filename,sheet,Range1)+273.15;
t_Nl = xlsread(filename,sheet,Range2)+273.15;
ydata = [t_Kl t_Nl];
p0 = ones(1,4);
pbest = fmincon(@(p)objective(p,ydata),p0);
end
function diff = objective(p,ydata)
tspan = linspace(0,3785,3785);
ic = [300 300];
f = @(t,T,p) [(p(1)*(T(2)-T(1))+p(2))/100; p(3)*(T(1)-T(2))+p(4)*(300-T(2))];
[t,T] = ode45(@(t,y)f(t,y,p),tspan,ic);
diff = sum(((T(:,1)-ydata(:,1))./ydata(:,1)).^2)+sum(((T(:,2)-ydata(:,2))./ydata(:,2)).^2);
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by