フィルターのクリア

Fit an Ordinary Differential Equation (ODE) using fmincon

14 ビュー (過去 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 Center および File ExchangeSolver-Based Nonlinear Optimization についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by