求高人帮解决一下本程序的问题
最近本人应用Matlab计算反应动力学参数,遇到了点问题。特此向各位高人请教。本人的程序如下:
clear all
clc
k0 = ;
lb = ;
ub = [+inf+inf+inf+inf+inf+inf];
x0 = ;
KineticsData65;
yexp = ExpData(:,2:7);
= fmincon(@ObjFunc4Fmincon,k0,[],[],[],[],lb,ub,[],[],x0,yexp);
fprintf('\n使用函数fmincon()估计得到的参数值为:\n')
fprintf('\tk1 = %.4f\n',k(1))
fprintf('\tk2 = %.4f\n',k(2))
fprintf('\tk3 = %.4f\n',k(3))
fprintf('\tk4 = %.4f\n',k(4))
fprintf('\tk5 = %.4f\n',k(5))
fprintf('\tk6 = %.4f\n',k(6))
fprintf('The sum of the squares is: %.1e\n\n',fval)
k_fmincon = k;
= ...
lsqnonlin(@ObjFunc4LNL,k0,lb,ub,[],x0,yexp);
ci = nlparci(k,residual,jacobian);
fprintf('\n\n使用函数lsqnonlin()估计得到的参数值为:\n')
Output
k0 = k_fmincon;
= ...
lsqnonlin(@ObjFunc4LNL,k0,lb,ub,[],x0,yexp);
ci = nlparci(k,residual,jacobian);
fprintf('\n\n以fmincon()的结果为初值,使用函数lsqnonlin()估计得到的参数值为:\n')
Output
% ------------------------------------------------------------------
function f = ObjFunc4Fmincon(k,x0,yexp)
tspan = ;
= ode45(@KineticEqs,tspan,x0,[],k);
y(:,1) = x(:,1);
y(:,2:5) = x(:,5:8);
f = sum((y(:,1)-yexp(:,1)).^2) + sum((y(:,2)-yexp(:,2)).^2) ...
+ sum((y(:,3)-yexp(:,3)).^2) + sum((y(:,4)-yexp(:,4)).^2)+ sum((y(:,5)-yexp(:,5)).^2);
% ------------------------------------------------------------------
function f = ObjFunc4LNL(k,x0,yexp)
tspan = ;
= ode45(@KineticEqs,tspan,x0,[],k);
y(:,1) = x(:,1);
y(:,2:5) = x(:,5:8);
f1 = y(:,1) - yexp(:,1);
f2 = y(:,2) - yexp(:,2);
f3 = y(:,3) - yexp(:,3);
f4 = y(:,4) - yexp(:,4);
f5 = y(:,5) - yexp(:,5);
f = ;
% ------------------------------------------------------------------
function dxdt = KineticEqs(t,x,k)
dxdt =...
[ ( -k(1)*x(1)*x(5)+k(2)*x(2)*x(4) )
( k(1)*x(1)*x(5)-k(2)*x(2)*x(4)-K(3)*x(2)*x(5)+K(4)*x(3)*x(4) )
( K(3)*x(2)*x(5)-K(4)*x(3)*x(4)-k(5)*x(3)*x(5)+k(6)*x(4)*x(6) )
( K(1)*x(1)*x(5)-K(2)*x(2)*x(4)+K(3)*x(2)*x(5)-k(4)*x(3)*x(4)+k(5)*x(3)*x(5)-k(6)*x(4)*x(6) )
( -K(1)*x(1)*x(5)+K(2)*x(2)*x(4)-K(3)*x(2)*x(5)+k(4)*x(3)*x(4)-k(5)*x(3)*x(5)+k(6)*x(4)*x(6) )
( k(5)*x(3)*x(5)-k(6)*x(4)*x(6) )
];
出现的错误提示为:
Warning: Large-scale (trust region) method does not currently solve this type of problem,
switching to medium-scale (line search).
> In fmincon at 260
In KineticsEst65 at 25
??? Error using ==> fmincon
FMINCON cannot continue because user supplied objective function failed with the following error:
Undefined command/function 'K'.
Error in ==> KineticsEst65 at 25
= fmincon(@ObjFunc4Fmincon,k0,[],[],[],[],lb,ub,[],[],x0,yexp);
请哪位高人帮我修改一下程序,非常感谢! 你是不是把大小写搞错了
回复 沙发 sigma665 的帖子
全一致改成小写了,还是相同的问题!这是怎么回事呢
修正一下
经全部符号对照修改后错误提示为
Warning: Large-scale (trust region) method does not currently solve this type of problem,
switching to medium-scale (line search).
> In fmincon at 260
In KineticsEst65 at 25
??? Error using ==> fmincon
FMINCON cannot continue because user supplied objective function failed with the following error:
Index exceeds matrix dimensions.
Error in ==> KineticsEst65 at 25
= fmincon(@ObjFunc4Fmincon,k0,[],[],[],[],lb,ub,[],[],x0,yexp);
回复 地板 hwkai 的帖子
提示的意思是叫你用线搜索的方法回复 5楼 无水1324 的帖子
请教一下,我该如何实现线搜索呢!这方面我不太懂啊。能帮我改一下吗 Index exceeds matrix dimensions.仔细看看你的矩阵维数 首先
你的ode45能不能解出答案 看看初值赋值是不是超出了范围
提示的意思是说你选用的算法规模太大不适合这个问题,建议换成较小的线性搜索
页:
[1]