利用fminconodeMatLab进行优化 [英] Optimization using fmincon ODE Matlab
本文介绍了利用fminconodeMatLab进行优化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问题是通过改变kst、x1、x5和xo,在(-8e-4到2e-4)的范围内找到x3的最佳(最大)值)
x5=5 %Input 2 (Input 2 is a state variable and could vary in range of 4 to 15 while performing
optimization)
kst=1 %Input 3 (Input 3 is in terms of rate constant, it could vary from 0.1 to 2)
xo=4 %Input 4 (Input 4 is a state variable and could vary in range of 4 to 10)
x1=1e-7 %Input 1 could vary from 1e-9 to 1e-6
- 脚本文件
function rest = Scrpt1(t,X)
x2 = X(1);
x3 = X(2);
%Parameters
if t<15
x1 = 1e-7; %Input 1 could vary from 1e-9 to 1e-6
else x1 = 0;
end
x5=5 %Input 2 (Input 2 is a state variable and could vary in range of 4 to 15 while performing optimization)
kst=1 %Input 3 (Input 3 is in terms of rate constant, it could vary from 0.1 to 2)
xo=4 %Input 4 (Input 4 is a state variable and could vary in range of 4 to 10)
k1 = 6e7;
km1 = 0.20;
km4 = 0.003;
k3 = 2500.00;
k4 = km4/9;
km3 = km1;
LAP=1.5
% Differential equations
dx2dt = km1*x3 + km3*LAP - k1*x1*x2 + km4*x3 - k4*x2;
dx3dt = k1*x1*x2 - km1*(x3+x5+xo) - k3*x3*kst;
rest = [dx2dt; dx3dt];
end
- ODE解决方案函数文件
options = odeset('InitialStep',0.0001,'RelTol',1e-09);
[T,Y]=ode15s(@Scrpt1,[0 60],[9e-13,0],options);
X3= Y(:,2);
plot(T,X3)
如何使用fmincon或任何其他优化求解器来解决前面提到的寻找x3的最大值的优化问题。对于x5、kst、x0、x1的哪个值,我们得到最大x3?
推荐答案
首先,您必须将要优化的值添加为耦合的微分方程式的参数:
function rest = Scrpt1(t,X,X_opt)
x5=X_opt(1);
kst=X_opt(2);
xo=X_opt(3);
x1=X_opt(4);
x2 = X(1);
x3 = X(2);
%Parameters
if t>=15
x1 = 0;
end
k1 = 6e7;
km1 = 0.20;
km4 = 0.003;
k3 = 2500.00;
k4 = km4/9;
km3 = km1;
LAP=1.5;
% Differential equations
dx2dt = km1*x3 + km3*LAP - k1*x1*x2 + km4*x3 - k4*x2;
dx3dt = k1*x1*x2 - km1*(x3+x5+xo) - k3*x3*kst;
rest = [dx2dt; dx3dt];
end
然后,您必须编写一个要最小化的包装函数。因为你想最大化x3,你必须在你的目标值上加一个减号。
function max_X3=fun(X_opt)
tspan=[0 60];
y0=[9e-13,0];
options = odeset('InitialStep',0.0001,'RelTol',1e-09);
[~,y] = ode15s(@(t,y) Scrpt1(t,y,X_opt), tspan, y0,options);
max_X3=-max(y(:,2));
end
最后,您可以这样使用fmincon:
% x5, kst, xo, x1
initial_search_point=[5, 1, 4, 1e-7]
lower_bounds=[4, 0.1, 4, 1e-9]
upper_bounds=[15, 2, 10, 1e-6]
fmincon(@fun,initial_search_point,[],[],[],[], lower_bounds,upper_bounds)
这篇关于利用fminconodeMatLab进行优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文