📄 stretch_func_fmincon.m
字号:
function [f,g] = ...
stretch_func_fmincon(X,sys_eq,ode_param,n_vector)
% Compute objective function for the optimization problem in the flow pipe
% segment approximation procedure for `nonlinear` dynamics, using fmincon.
%
% Syntax:
% "f = stretch_func_ode(X,sys_eq,ode_param,n_vector)"
%
% Description:
% Compute the following objective function value for the given "x0" and "t"
%
%
%
% "max (x0 in X0, t in [0,T]) n_vector'*x(t,x0)"
%
%
%
% where "n_vector" is the normal vector and "x(t,x0)" denotes the solution
% to the nonlinear differential equation.
%
% Implementation:
% The ODE solution "x(t,x0)" is computed for the given "t" and "x0" using
% the ODE solver "ode45" in MATLAB. The optimization variables for the
% objective function are passed in as a single variable "X" whose first
% "n" element is the vector "x0" and last element is the time "t". The
% objective function for the optimization is a function of "X"
% only. "ode_param" contains optional parameters for the ODE file
% (see MATLAB help on "odefile" for more detail).
%
% See Also:
% seg_approx_ode, stretch_func_ode, stretch_const_fmincon
n = length(X)-1;
x0 = X(1:n,1);
t = X(n+1,1);
if (t ~= 0)
[T,Xtraj] = ode45(sys_eq,[0 t],x0,[],ode_param);
last = length(T);
xt = Xtraj(last,:)';
else
xt = x0;
end
% objective function value
f = -n_vector'*xt;
return
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -