fminunc for upper and lower bound variable definition ?

Isn't it possible to give upper and lower bound for the variables in the objective function while using fminunc ?
Thank you.

 Accepted Answer

No, fminunc() is for unconstrained optimization. If you want to do constrained optimization, then use fmincon().

2 Comments

right, fminunc is UNConstrained
Is fmincon() quasi-newton as well ?
Thank

Sign in to comment.

More Answers (1)

You could transform variables, x will be opened bounded by lo/hi
xfun = @(y) lo + (hi-lo).*sin(y).^2
...
y = fminunc(obj(xfun(y)), ...)
x = xfun(y)
Honestly I don't like those kind of transformation.
Use the right tool: fmincon as others have suggested.

9 Comments

sin(y) could be negative though
Good catch Walter, I correct it
Could also use the midpoint plus half the difference times sine unsquared, taking advantage of the negative ;)
I could. Just minimize the keyboard skrokes while editing the code. ;-)
The UB and LB are vectors and my atempt gives me error message. Isn't it possible to define as vector ?
x1U=1; % in m
x1L=0.7; % in m
x2U = deg2rad(150);
x2L = deg2rad(120);
x3L = deg2rad(-150);
x3U = deg2rad(-120);
x1=x1L:(x1U-x1L)/ts:x1U;
x2=x2L:(x2U-x2L)/ts:x2U;
x3=x3L:(x3U-x3L)/ts:x3U;
x=[x1;x2;x3];
fun = @(x)[x1L;x2L;x3L]+([x1U;x2U;x3U]-[x1L;x2L;x3L]).*PRSopt_QN1(x(1,:),x(2,:),x(3,:))
Error using fmincon (line 383)
Supplied objective function must return a scalar value.
Error in Main_Opt (line 21)
[xOptimal,V] = fmincon(fun,x,options)
No, fmincon() is completely unsuited for finding the minimum of multiple functions at the same time. See gamultiobj()
HN
HN on 5 Nov 2020
Edited: HN on 5 Nov 2020
Walter Roberson, Would you please explain it a bit more? I actually didn't want to us GA. From physical point of view the objective function is one but a vector in its dimension. It takes a vector input and return a scalar which is the average of a vector. But, what confuses me is the way to define UB and LB of the input vector.
Thanks
fun = @(x)[x1L;x2L;x3L]+([x1U;x2U;x3U]-[x1L;x2L;x3L]).*PRSopt_QN1(x(1,:),x(2,:),x(3,:))
Unless two of x1L, x2L, x3L are empty and the third is a scalar, then you can be sure that function is going to return something that is not a scalar. You do not take the mean() there.
Thank you Walter Roberson,
I correct it like this. But it only gives some of the output arguments . Moreover, How can I define the option without defined Hessian ? Thanks
A = [];
b = [];
Aeq = [];
beq = [];
%%
LB = [deg2rad(120),deg2rad(-150)];
UB= [deg2rad(150),deg2rad(-120)]
x=[1;deg2rad(130);deg2rad(-130)];
fun = @(x)PRSopt_QN(x(1),x(2))
% [V,fval] = fmincon(fun,x)
[V,fval,exitflag,output,lambda,grad,hessian] = fmincon(fun,x,A,b,Aeq,beq,LB,UB)
AverageF=PRSopt_QN(x(1,:),x(2,:));

Sign in to comment.

Asked:

HN
on 4 Nov 2020

Edited:

HN
on 5 Nov 2020

Community Treasure Hunt

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

Start Hunting!