Optimize an objective function for values plus or minus near zero.
15 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am trying to optimize a function that I have defined. The problem is that the function defines acceleration at a revolute joint and of course must take on negative and positive values. I am having a hard time coming up with a way to constrain my objective function so that I can minimize it near zero. Basically, I don’t care how large the value is, but I want the output to be as close to zero as it possibly can, given my constraints. Please forgive if I have implemented any bad practices but I have attached my objective function (using the ub,lb, and while loop addition was my attempt at limiting the objective) and constraints. All recommendations are welcome. Please let me know if any more information is needed.
First is my objective function. Also, note that I have cut the A = .... way down since it may not be necesary, but if you need to see it all let me know.
function A = Objective(x)
%Objective Function
% Objective function to minimize accelerations for 6DOF arm
th1 = x(1);
th2 = x(2);
th3 = x(3);
th4 = x(4);
thdot1 = x(5);
thddot1 = x(6);
thdot4 = x(7);
thddot4 = x(8);
tau1f = x(9);
tau2f = x(10);
tau3f = x(11);
T = x(12);
ub = x(13); % Upper bounds of objective function
lb = x(14); % Lower bounds of objective function
A = 0;
flag = 0;
while (A >= lb) || (A <= ub)
if ((T >= 0) && (T <= tau1f)) % First segment of Acceleration.
A = thddot1+(T^2*1.0/tau1f^4*(tau2f^3*tau3f*th1*1.8e1-tau2f^3*tau3f*th2*1.8e1+tau1f^2*tau
elseif ((T > tau1f) && (T <= tau1f+tau2f)) % Second segment of Acceleration.
T = T - tau1f;
A = (tau1f*tau2f^2*th3*1.2e1-tau1f*tau3f^2*th2*6.0+tau2f*tau3f^2*th1*1.2e1+tau2f^2*tau3f*
else
T = T - (tau1f + tau2f); % Third segment of Acceleration.
A = -(tau1f*tau2f^2*th3*2.4e1+tau1f^2*tau2f*th3*1.2e1-tau1f^2*tau3f*th2*6.0+tau2f^2*tau3f
end
flag = flag + 1;
if flag == 1000
break
end
end
end
And for my constraints:
% x = [th1;th2;th3;th4;thdot1;thddot1;thdot4;thddot4;tau1f;tau2f;tau3f;T;ub;lb];
A1eq = [1 0 0 0 0 0 0 0 0 0 0 0 0 0;... % Linear equality
0 0 0 1 0 0 0 0 0 0 0 0 0 0;...
0 0 0 0 1 0 0 0 0 0 0 0 0 0;...
0 0 0 0 0 1 0 0 0 0 0 0 0 0;...
0 0 0 0 0 0 1 0 0 0 0 0 0 0;...
0 0 0 0 0 0 0 1 0 0 0 0 0 0;...
0 0 0 0 0 0 0 0 0 0 0 1 0 0;...
0 0 0 0 0 0 0 0 1 1 1 0 0 0;...
0 0 0 0 0 0 0 0 0 0 0 0 1 0;...
0 0 0 0 0 0 0 0 0 0 0 0 0 1];
b1eq = [0;85;0;0;0;0;9;9;50;-50]; % Linear equality
A1 = [0 -1 0 0 0 0 0 0 0 0 0 0 0 0;... % Linear inequality
0 1 0 0 0 0 0 0 0 0 0 0 0 0;...
0 0 -1 0 0 0 0 0 0 0 0 0 0 0;...
0 0 1 0 0 0 0 0 0 0 0 0 0 0;...
0 0 0 0 0 0 0 0 -1 0 0 0 0 0;...
0 0 0 0 0 0 0 0 1 1 1 0 0 0;...
0 0 0 0 0 0 0 0 0 -1 0 0 0 0;...
0 0 0 0 0 0 0 0 0 0 -1 0 0 0;...
0 0 0 0 0 0 0 0 -1 -1 -1 0 0 0];
b1 = [0;85;0;85;0;9;0;0;0]; % Linear inequality
x10 = [0;40;40;85;0;0;0;0;2;2;2;9;50;-50]; % Start point
Thanks in advance for any help
8 Kommentare
Matt J
am 31 Mär. 2019
The solver will never produce a result that satisfies the inequality constraints exactly, but they should satisfy them within the ConstraintTolerance input parameter.
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Get Started with Optimization Toolbox finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!