Minimize cost function (4-d integral)

조회 수: 11 (최근 30일)
Arina Pirogova
Arina Pirogova 2024년 1월 12일
편집: Torsten 2024년 1월 15일
I want to integrate this cost function symbolically in order to later find its minimum using fmincon():
where K:
and , depend on , , , , , , θ. However, the int() function fails to integrate. The example 4-D Integral of Sphere is not suitable, since there the integral is calculated numerically.
  댓글 수: 10
Arina Pirogova
Arina Pirogova 2024년 1월 15일
편집: Arina Pirogova 2024년 1월 15일
%Constants:
mu = 55;
delta = 1;
k = 0.142857;
g = 9.8;
if you assign these values to variables, then fmincon throws an error: Input function must return ‘double’ or ‘single’ values. Found 'sym'.
I tried to substitute x_0 into the function f to check its functionality. It didn't work for the same reason. So, please explain how to pass the value psi_i, phi_i to the function f, since there is only I3, and their dependence is not specified.
Torsten
Torsten 2024년 1월 15일
편집: Torsten 2024년 1월 15일
Check whether this is really what you want. The construction is quite complicated, and the evaluation of your function F takes a while.
%% Symbolic work section
syms theta ddtheta ddx ddz psi1 psi2 phi1 phi2
%Constants:
mu = 55;
delta = 1;
k = 0.142857;
g = 9.8;
% Some matrix A
A = [1 cos(phi1) cos(phi2);
0 sin(phi1) sin(phi2);
0 sin(psi1)/abs(sin(psi1+phi1)) sin(psi2)/abs(sin(psi2+phi2))];
% Some matrix theta (looks like a Rotation Matrix)
T_theta = [cos(theta) sin(theta) 0;
-sin(theta) cos(theta) 0;
0 0 1];
% Some matrix B
B = [ddx;
ddz+k*g;
mu*ddtheta];
% Maybe some state equations?
U = inv(A)*T_theta*B;
u0 = abs(U(1));
u1 = abs(U(2));
u2 = abs(U(3));
UU = simplify(u0 + u1 + u2);
%% Numerical work section
func = matlabFunction(UU, 'Vars', [theta, ddtheta, ddx, ddz, psi1, psi2, phi1, phi2]);
I3 = @(theta,psi1,psi2,phi1,phi2) integral3(@(ddtheta, ddx, ddz) func(theta, ddtheta, ddx, ddz, psi1, psi2, phi1, phi2), -delta/mu, delta/mu, -delta, delta, -delta, delta);
% The cost function
f = @(psi1, psi2, phi1, phi2) integral(@(theta)I3(theta,psi1,psi2,phi1,phi2), -pi, pi, 'ArrayValued',1);
F = @(x)f(x(1),x(2),x(3),x(4));
psi1_0 = 3*pi/4; % for x_0
psi2_0 = 0; % for x_0
phi1_0 = 5*pi/12; % for x_0
phi2_0 = 7*pi/4; % for x_0
x_0 = [psi1_0,psi2_0,phi1_0,phi2_0]; % initial guess
lb = [0,pi,0,pi]; % lower bound
ub = [pi,2*pi,pi,2*pi]; % upper bound
%% call fmincon solver
[x, fval] = fmincon(F, x_0, [], [], [], [], lb, ub, @non_linear)
%% Nonlinear constraints:
function [c, ceq] = non_linear(x)
c = [-abs(tan(x(1) + x(3))) + 0.2; % <-- unsure if the bracket is placed correctly
-abs(tan(x(2) + x(4))) + 0.2]; % <-- unsure if the bracket is placed correctly
ceq = [];
end

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Conversion Between Symbolic and Numeric에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by