Optimization of function of 3 variables
Show older comments
f(x,y,z)=(1./(2.*y.^2)).*(x+(2.*y.^2-x).*cos(z)+sqrt(x.^2.*(cos(z)-1).^2+4.*y.^2.*(x-y.^2).*(sin(z)).^2));
constraints: x>y^2; y>0; z>0;
How can i find minimum value of f atMATLAB?
Answers (1)
John D'Errico
on 7 Mar 2022
1 vote
You need first to define this as a function handle.
Then you need to use FMINCON as the solver, or GA will also work. The constraints on y and z are lower bound constraints. There will be no explicit lower bound on x, but that gets handles by the nonlinear inequality anyway. The constraint x>=y^2 is a nonlinear constraint.
Note that you cannot define strict inequality constraints, thus using > as the inequality. You can only have >= as an inequality. And even then the inequality may fail by as much as the constraint tolerance.
Since this is probably homework, I won't write the code for you, but if you show an effort in a comment at writing the code, I would help you to correct it.
7 Comments
Anthony Cherrington
on 22 Mar 2022
my function is f(x,y,z)=x+y+(z^2)
with constraints (x^2)+(y^2)+(z^2) = 1 and y=0
I made a seperate function file constraints.m for my nonlinear constraint and this is the code i'm using for my fmincon but it won't run at all I'm not sure how to fix it please help!!!
fun = @(x,y,z)x+y+z^2;
A=[];
b=[];
Aeq=[0 1 0];
beq= 0;
lb=[];
ub=[];
nonlcon= @constraint;
x0=[0,0,0];
options = optimoptions('fmincon','Display','iter','Algorithm','sqp');
x = fmincon(fun,x0,A,b,beq,lb,ub,nonlcon,options);
Walter Roberson
on 22 Mar 2022
fmincon passes a vector, not individual variables.
John D'Errico
on 22 Mar 2022
Your function is NOT:
f(x,y,z)=x+y+(z^2)
It is
f = @(xyz) xyz(1) + xyz(2) + xyz(3).^2;
Walter Roberson
on 22 Mar 2022
my function is f(x,y,z)=x+y+(z^2)
with constraints (x^2)+(y^2)+(z^2) = 1 and y=0
substitute the y=0 into the constraint, getting x^2 + z^2 = 1. Isolate z^2 = 1-x^2. Substitute into x+0+z^2 to get x + 1 - x^2 as the objective function. By examination that goes to negative infinity as x goes to negative infinity. As x goes to infinity you might worry that it has a negative infinity plus infinity but the -x^2 goes "faster" than the +x so you should be ok in the limit.
A minimizer could potentially end up bouncing around between the negative and positive branches, depending how it is implemented. The result could depend on the starting point (and not necessarily in a simple way.)
Torsten
on 22 Mar 2022
Walter Roberson
on 22 Mar 2022
Good point ✅
...On the other hand we have not been told to restrict to real-valued 😁
Torsten
on 22 Mar 2022
:-)
Categories
Find more on Choose a Solver in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!