find the global optimum

조회 수: 12 (최근 30일)
Ondrej Labik
Ondrej Labik 2021년 2월 2일
댓글: Ondrej Labik 2021년 2월 10일
Hello,
I am new to matlab and I have to find the global optimum of this function with those constrains. Could you please help me out?
Thank you

답변 (1개)

Shubham Rawat
Shubham Rawat 2021년 2월 8일
Hi,
You may use this code for your reference:
%initializing variables
x = optimvar('x');
y = optimvar('y');
prob = optimproblem;
%writing objective
prob.Objective = 2*x + y;
%writing Constraints
prob.Constraints.cons1 = 1.25-x^2-y<=0;
prob.Constraints.cons2 = x+y<=1.6;
prob.Constraints.cons3 = x <=1.6;
prob.Constraints.cons4 = x >=0;
prob.Constraints.cons5 = y >=0;
prob.Constraints.cons6 = y <=1;
%initial Point
x0.x = 1;
x0.y = 0;
%solver with fmincon as optimization technique
options = optimoptions('fmincon');
sol = solve(prob, x0,'options',options);
%displaying result
fval = evaluate(prob.Objective,sol)
You may also use this documentation :
Hope this Helps!
  댓글 수: 1
Ondrej Labik
Ondrej Labik 2021년 2월 10일
Thank you so much!
I actually found a way how to use fmincon function to solve it, where I did loops with different values for y and compare the fvalues. But this looks way more sophisticated.
Thanks

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

카테고리

Help CenterFile Exchange에서 Linear Least Squares에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by