How to set a target in the Optimisation Toolbox?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Greetings, I have the following code which simply finds a value which maximises the area of a square.
Lets say I want the Area to be not maximum but lets say 23. (or any number between 0 and max value). How can I set such a goal ?
Any help would be much appreciated.
Optim.m
clc; clear all; close all
FitnessFunction = @SquareF;
numberOfVariables = 1;
A = []; b = [];
Aeq = []; beq = [];
lb = 0;
ub = 1;
options = optimoptions(@gamultiobj,'PlotFcn',{@gaplotscorediversity,@gaplotstopping,@gaplotspread});
[x,Volume] = gamultiobj(FitnessFunction,numberOfVariables,[],[],[],[],lb,ub,options);
formatSpec = 'Max Area is %5f\n';
fprintf(formatSpec,Volume)
and
SquareF.m
function y = SquareF(x)
%y(1) = (x+2)^2 - 10;
Lt = 10; % Total Perimeter Length Available
A = Lt*x(1); % Side A
B = Lt-A; % Side B
y(1) = -A*B; %Area m^2
rL = A+B;
end
0 Kommentare
Akzeptierte Antwort
Matt J
am 18 Nov. 2021
Bearbeitet: Matt J
am 18 Nov. 2021
Lets say I want the Area to be not maximum but lets say 23. (or any number between 0 and max value)
It sounds like you are saying you want to maximize area but with the constraint that the area can be no larger than 23 and the perimeter no greater than Lt. For a square, that's the same as saying that the length of the side x is bounded above by min( sqrt(23), Lt/4).
Lt=15;
lb=0;
ub=min( sqrt(23), Lt/4);
fun=@(x) -x^2; %objective
[x,negativeArea]=fmincon(fun,sqrt(23),[],[],[],[],lb,ub)
1 Kommentar
Matt J
am 18 Nov. 2021
Bearbeitet: Matt J
am 18 Nov. 2021
Alternatively, you might be saying you want to bring the area as close to 23 as possible, but still with the constraint that the perimeter is <=Lt, If so, then that would be as below, but happens to give the same result.
Lt=15;
lb=0;
ub=Lt/4;
fun=@(x) (23-x^2).^2; %objective
x=fmincon(fun,sqrt(23),[],[],[],[],lb,ub)
Area=x.^2
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Surrogate Optimization 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!