我正在优化实验数据的模拟。问题是我有一系列数据。我使用LSQNONLIN进行了优化,并且它非常适合一系列数据的参数。 现在,我正在尝试对所有系列数据进行优化。问题在于,当我这样做时,与第一次模拟(优化之前)相比,我得到的结果更差,结果远非优化。 我的代码在这里。它没有任何错误。我不知道如何解决这个问题。有人能帮助我吗?
%% MAIN FUNCTION
% Import constant data to the main function
[Input,options] = input_data(mC,mH,mO); % This function read all excel sheet and calculate some parameters which are constant for each iteration
% Lower bound
lb = 1e-30*ones(12,1);
% Initial guess
k0 = [6.2489,6.5724,2.1093,1.6735,6.8555,2.1517,3.4014,2.1483,5.7985,9.5707,4.427,1];
% Options for "lsqnonlin"
oldoptions = optimset('Display', 'iter' ,...
'Diagnostics', 'on' ,...
'Algorithm', 'trust-region-reflective' ,...
'FinDiffType', 'central' ,...
'FinDiffRelStep', 1e-03 ,...
'MaxFunEvals', 5000 ,...
'MaxIter', 200 ,...
'TolX', 1e-16 ,...
'TolFun', 1e-14);
% Parameter estimation
[k,resnorm,residual,exitflag,output] = lsqnonlin(@(k)PFR(k,Input,options,std_dev,MW_E),k0,lb,[],opts);
%% OBJECTIVE FUNCTION: This function calculates the difference between simulation concentrations and experimental concentrations for all excel sheets
function final = PFR(k,Input,options,std_dev,MW_E)
final = [];
for w = 1:length(Input.ndata)
% Integration
[z,f] = ode23tb(@(z,g)PFR_DGL(z,g,Input.n,Input.URH{w,1},k,Input.kTu{w,1},Input.n_u),Input.zspan{w,1},Input.f0{w,1},options);
% Concentration of species which their experimental concentrations are exist
final_f = f(:,[2:6]);
% Experimental concentrations in mol/m³
conc_E = Input.ndata{w,1}(:,9:12).*Input.rhoRH{w,1}*1000;
% Difference between simulation concentrations and experimental concentrations
conc_diff = final_f - final_E;
% Transfer from matrix to a column vector
conc_diff_to_vector = conc_diff(:);
% Adding new conc_diff_to_vector (resulted from the new excel sheet) in the continue of last ones
final = [final; conc_diff_to_vector]; % final would be a column vector
end
%%THIS FUNCTION IS USED BEY ODE
function f = PFR_DGL(z,g,n,URH,k,kTu,n_u)
% Reaction rate function
ru = rate_Po2_u(g(1:n),k,kTu); % this function included the parameters which should be estimated
% Output
f(1:n) = ((n_u'*ru)/URH);
%% THIS FUNCTION INCLUDED THE PARAMETERS WHICH SHOULD BE ESTIMATED
function ru = rate_Po2_u(c,k,kTu)
% "k" shows estimated parameters; "kTu" shows the parameters which are calculated in "input_data" function
ru = [ k(1)*c(1)*c(2)
kTu(2)*c(3)*c(2)
k(2)*c(1)*c(5)
.
.
.
kTu(20)*c(1)*c(7)
k(11)*c(12)];
function [Input,options] = input_data()
% This function reads all excel sheets and calculate some parameters which are constant for each iteration
% The stoichiometric coefficient matrix
Input.n_u = [a matrix]
% Collision factors,
k0u = [a row vector];
% Activation Energies,
Eu = [a row vector];
% Import data from excel sheets
ex = actxserver('excel.application');
for w = 1:3 % 3 = number of excel sheets that the program wants to read
ex.Workbooks.Open(['C:\Users\Measurements\',num2str(w),'results.xls']);
ndata = get(ex.Range('A1:A22:U1:U22'),'Value');
%% Input Parameters
% Pressure, bar -> Pa
pin = Input.ndata(1,3); % Column C
Input.p0 = pin*1e5;
.
.
%% Material Parameters
% Molar density of the liquid phase
mrhoRH = density_RH(Input.T0);
.
.
% Reaction rate constant at temperature T, various units
Input.kTu = k0u.*exp(-Eu*RTi);
% Interval of integration vector
Input.zspan = linspace(0,LR,100);
end
ex.Quit
% Options for the ODE solver
options = odeset('RelTol',1.0e-10, 'AbsTol',1.0e-12, 'InitialStep',1e-03);
提前致谢,