optimization for min and max values of a parameter

Im trying to optimize a kind of 4 bar mechanism (lenghts to minimize forces) which has to move within predefined min&max values of an angle as lower and upper bounds. l want my optimization to run according to taking those values into account in the objective function and nonlinear constraints where my system has to reach while working.(Defining the angle as a variable with upper/lower bounds leads to result of finding optimums of the angle too). creating a for loop to iterate every single movement is a good idea? how should l define those min max values? its simple version is below,
Angmin = -30;
Angmax = 30;
Ang = Angmin & Angmax;% optimizan process must take both values into account in the same process.
A =[];
b = [];
Aeq =[];
beq= [];
lb = [];
ub = [];
x0= [40,50,60,70];
function Fmin = minconfcn(x)
Fmin = (x(2)/x(1))*sqrt(x(3)^2+x(2)^2)*cos(x(4)+Ang)
end
function [c,ceq] = nlincnstfcn(x)
c(1) = asin(x(4)+Ang) + x(3)^2 - x(1)^2;
c(2) = sqrt((x(2)*asin(Ang))^2- x(2)^2)+x(1);
ceq = [];
end
[x,Fmin] = fmincon(@minconfcn,x0,A,b,Aeq,beq,lb,ub,@nlincnstfcn)

댓글 수: 8

If you write a formal mathematical description of the problem for us, it would be easier to say. Basically, though, all Optimization Toolbox solvers allow you to impose upper and lower bounds on the unknown parameters, and fmincon allows you to apply arbitrary (differentiable) nonlinear constraints.
gigi
gigi 2022년 2월 28일
편집: gigi 2022년 2월 28일
l firstly did the same thing you suggest, l defined the angle as a variable and its bounds. But optimization ends with finding minimized obj function and the angle (within bounds) for this purpose. My aim is to find minimized obj function while calculating the function for both min value and max value of the angle. l think it should be a kind of passing variable extra parameter but l dont know how to do it.
Again, a formal mathematical description would let us be more helpful.
l added its basic description
Why though is Ang a vector with 61 different values? You made it sound like you had only 2 values, an upper and lower bound.
you can think it as 2 values, min and max too.
No you can't think of 61 values as 2 values. Matlab won't see it that way.
l editted the description

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

답변 (2개)

Matt J
Matt J 2022년 2월 28일
편집: Matt J 2022년 2월 28일
l think it should be a kind of passing variable extra parameter but l dont know how to do it.
One way is to use nested functions, as below. See also Passing Extra Parameters - MATLAB & Simulink.
function main()
Angmin = -30;
Angmax = 30;
A =[];
b = [];
Aeq =[];
beq= [];
lb = [];
ub = [];
x0= [40,50,60,70];
[x,Fmin] = fmincon(@minconfcn,x0,A,b,Aeq,beq,lb,ub,@nlincnstfcn)
function Fmin = minconfcn(x)
Fmin = (x(2)/x(1))*sqrt(x(3)^2+x(2)^2)*cos(x(4))
end
function [c,ceq] = nlincnstfcn(x)
c(1) = asin(x(4)+Angmin) + x(3)^2 - x(1)^2;
c(2) = sqrt((x(2)*asin(Angmax))^2- x(2)^2)+x(1);
ceq = [];
end
end

댓글 수: 7

this is not the desired one, in this case it only take one value (max) into account.
You can pass as many variables as you like in the same manner.
l want my optimization to consider min and max at the same time, not induvidually.
I have rewritten my answer to show (in hypothetical equations) how Angmin and Angmax can both be manipulated by your constraints. That should be enough. What the actual constraint equations should be is up to you to provide. No one here besides you can possibly know the physics of your problem.
gigi
gigi 2022년 3월 1일
편집: gigi 2022년 3월 1일
why l need to delete Ang from the equation in obj function? the result will be wrong in that case.
Again, all of the equations I have written are deliberately wrong. Only you can provide the correct equations. My role here was to show how to make other variables like Angmin avaialble to the objective function and constraints.
Thank you so much for your helpful suggests and supports, but this method doesnot solve the issue. Any different suggests will be appricated if you have.

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

Torsten
Torsten 2022년 3월 2일
편집: Torsten 2022년 3월 2일
function main
Angmin = -30*pi/180;
Angmax = 30*pi/180;
A =[];
b = [];
Aeq =[];
beq= [];
lb = [-Inf -Inf -Inf -Inf Angmin];
ub = [Inf Inf Inf Inf Angmax];
x0= [40,50,60,70*pi/180,10*pi/180];
[x,Fmin] = fmincon(@minconfcn,x0,A,b,Aeq,beq,lb,ub,@nlincnstfcn)
end
function Fmin = minconfcn(x)
Fmin = (x(2)/x(1))*sqrt(x(3)^2+x(2)^2)*cos(x(4)+x(5))
end
function [c,ceq] = nlincnstfcn(x)
c(1) = asin(x(4)+x(5)) + x(3)^2 - x(1)^2;
c(2) = sqrt((x(2)*asin(x(5)))^2- x(2)^2)+x(1);
ceq = [];
end

댓글 수: 8

gigi
gigi 2022년 3월 2일
편집: gigi 2022년 3월 2일
in this case it will find the best Ang value within its limits to sustain Fmin. My desire is to sustain Fmin while calculating it at Angmin and Angmax at the same process.
Sorry, I don't understand.
you defined the Ang as a variable therefore optimization finds optimum angel for the Fmin. Therefore, Ang should pass as an extra parameter.
So you want "ang" to be constant during the optimization in your case, but you want to find the respective solutions for "ang" varying between Angmin and Angmax ?
ang must take two values Angmin and Angmax and obj function has to extract one solution according to them, not as Fmin(1) and Fmin(2). Passing them as a vector result in two Fmin, and l can find average of them and average of variables but this is not the right solution or method l think.
Torsten
Torsten 2022년 3월 2일
편집: Torsten 2022년 3월 2일
So you want to solve the problem for ang = Angmin and ang = Angmax separately and compare the respective values of the objective function (i.e. which solution is the better one) ?
function main
Angmin = -30*pi/180;
Angmax = 30*pi/180;
A =[];
b = [];
Aeq =[];
beq= [];
lb = [];
ub = [];
x0= [40,50,60,70*pi/180];
Ang = Angmin;
[x1,Fmin1] = fmincon(@(x)minconfcn(x,Ang),x0,A,b,Aeq,beq,lb,ub,@(x)nlincnstfcn(x,Ang))
ang = Angmax;
[x2,Fmin2] = fmincon(@(x)minconfcn(x,Ang),x0,A,b,Aeq,beq,lb,ub,@(x)nlincnstfcn(x,Ang))
end
function Fmin = minconfcn(x,Ang)
Fmin = (x(2)/x(1))*sqrt(x(3)^2+x(2)^2)*cos(x(4)+Ang)
end
function [c,ceq] = nlincnstfcn(x,Ang)
c(1) = asin(x(4)+Ang) + x(3)^2 - x(1)^2;
c(2) = sqrt((x(2)*asin(Ang)))^2- x(2)^2)+x(1);
ceq = [];
end
Not separately, together...
Then please write down what your objective function and the constraints are if you use Argmin and Argmax together in one run of fmincon. My phantasy has come to an end.

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

카테고리

도움말 센터File Exchange에서 Systems of Nonlinear Equations에 대해 자세히 알아보기

질문:

2022년 2월 28일

댓글:

2022년 3월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by