solve function with two variables by ga toolbox
1 次查看(过去 30 天)
显示 更早的评论
hello,
I have a function with two variables ang i want to optimize the function by using ga. I used the toolbox long time ago and i forgot how to use it. Can any one help me please.
my function is
y= 0.25-4.27*x(1)+0.61*x(2)+13.34*x(1)*x(2)-4.69*x(2).^2;
and the range of the variables are
lb = [0.001,0.01];
ub = [0.045,0.1];;
I'm trying to use
numberOfVariables = 2;
[x,fval] = ga(FitnessFunction,numberOfVariables,lb,ub)
Thanks
0 个评论
采纳的回答
Walter Roberson
2023-5-21
format long g
FitnessFunction = @(x) 0.25-4.27*x(1)+0.61*x(2)+13.34*x(1)*x(2)-4.69*x(2).^2;
lb = [0.001,0.01];
ub = [0.045,0.1];
numberOfVariables = 2;
A = []; b = [];
Aeq = []; beq = [];
[x,fval] = ga(FitnessFunction, numberOfVariables, A, b, Aeq, beq, lb, ub)
%cross-check
[xf, fvalf] = fmincon(FitnessFunction, randn(numberOfVariables, 1), A, b, Aeq, beq, lb, ub)
更多回答(1 个)
Sulaymon Eshkabilov
2023-5-21
Here is how it can be solved with GA:
lb = [0.001, 0.01];
ub = [0.045, 0.1];
numberOfVariables = 2;
y=@(x) 0.25-4.27*x(1)+0.61*x(2)+13.34*x(1)*x(2)-4.69*x(2).^2;
options = optimoptions('ga','PlotFcn', @gaplotbestf);
[x,fval] = ga(y,numberOfVariables,[],[],[],[],lb,ub, [], options)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Direct Search 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!