Filter löschen
Filter löschen

optimization for min and max values of a parameter

9 Ansichten (letzte 30 Tage)
gigi
gigi am 28 Feb. 2022
Kommentiert: Torsten am 2 Mär. 2022
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 Kommentare
Matt J
Matt J am 28 Feb. 2022
No you can't think of 61 values as 2 values. Matlab won't see it that way.
gigi
gigi am 28 Feb. 2022
l editted the description

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Matt J
Matt J am 28 Feb. 2022
Bearbeitet: Matt J am 28 Feb. 2022
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 Kommentare
Matt J
Matt J am 1 Mär. 2022
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.
gigi
gigi am 2 Mär. 2022
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.

Melden Sie sich an, um zu kommentieren.


Torsten
Torsten am 2 Mär. 2022
Bearbeitet: Torsten am 2 Mär. 2022
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 Kommentare
gigi
gigi am 2 Mär. 2022
Not separately, together...
Torsten
Torsten am 2 Mär. 2022
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Get Started with Optimization Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by