Minimize cost function (4-d integral)

14 views (last 30 days)
Arina Pirogova
Arina Pirogova on 12 Jan 2024
Edited: Torsten on 15 Jan 2024
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 Comments
Arina Pirogova
Arina Pirogova on 15 Jan 2024
Edited: Arina Pirogova on 15 Jan 2024
%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 on 15 Jan 2024
Edited: Torsten on 15 Jan 2024
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

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!