How to optimize two optimization variables within the same objective function?

I need to optimize (two optimization variables) as follow
f(x) min (X+Y) s.t (n,m)
y1 = sum(a1+n+c1-d1+(n1/S));
y2 = sum(a1+n+c1-d2+(n2/S));
y3 = sum(a1+n+c1-d3+(n3/S));
y4 = sum(a1+n+c1-d4+(n4/S));
y5 = sum(a1+n+c1-d5+(n5/S));
X = 0.125 * (y1 + y2+ y3+ y4+ y5);
y6 = sum(a2+m+c2-d6+(n6/S));
y7 = sum(a2+m+c2-d7+(n7/S));
y8 = sum(a2+m+c2-d8+(n8/S));
y9 = sum(a2+m+c2-d9+(n9/S));
Y= 0.25 * (y6 + y7+ y8+ y9);
fun = @(n,m)extension(n,m,a1,a2,c1,c2,d1,d2,d3,d4,d5,d6,d7,d8,d9,n1,n2,n3,n4,n5,n6,n7,n8,n9,S);
A = []; B = []; %linear inequality constrains
Aeq = []; beq = []; %linear equality constraints
lb = [0 0]; ub = [10 10];

3 Comments

Looks like n = m = 0 is the solution.
Best wishes
Torsten.
Thanks a lot Mr. Torsten for your quick response.
To avoid Zeros solutions what is the apporpirate way to develop this objective fun??
How can you avoid a zero solution? You said you wanted a minimum. That is where the function is at its minimum value. "Developing the objective function" has no meaning. It is what it is.

Sign in to comment.

Answers (1)

Yes. I agree with Torsten. And just think! You saved the time of trying to figure that out with an optimizer.
Were you to try to use one, you need to create a VECTOR of length 2, containing the values of n and m. The optimizer will vary those values. But don't bother, since it is [0,0].

5 Comments

Actually I tried (fmincon) as follow:
function y = extension(b,a1,a2,c1,c2,d1,d2,d3,d4,d5,d6,d7,d8,d9,n1,n2,n3,n4,n5,n6,n7,n8,n9,S)
y1 = sum(a1+b(1)+c1-d1+(n1/S));
y2 = sum(a1+b(1)+c1-d2+(n2/S));
y3 = sum(a1+b(1)+c1-d3+(n3/S));
y4 = sum(a1+b(1)+c1-d4+(n4/S));
y5 = sum(a1+b(1)+c1-d5+(n5/S));
X = 0.125 * (y1 + y2+ y3+ y4+ y5);
y6 = sum(a2+b(2)+c2-d6+(n6/S));
y7 = sum(a2+b(2)+c2-d7+(n7/S));
y8 = sum(a2+b(2)+c2-d8+(n8/S));
y9 = sum(a2+b(2)+c2-d9+(n9/S));
Y= 0.25 * (y6 + y7+ y8+ y9);
y = X + Y;
fun = @(b)extension(b, a1,a2,c1,c2,d1,d2,d3,d4,d5,d6,d7,d8,d9,n1,n2,n3,n4,n5,n6,n7,n8,n9,S);
A = []; B = []; %linear inequality constrains
Aeq = []; beq = []; %linear equality constraints
lb = [0 0]; ub = [10 10];
[b, fval] = fmincon(fun, b0, A, B, Aeq, beq, lb, ub);
Since (fmincon) attempts to find a minimizer b of the function described in fun, how could I get the different values of b(1) & b(2)?
"how could I get the different values of b(1) & b(2)"
?? Do you mean that you want a record of all b(1) and b(2) values that were attempted by fmincon ?
Thank you for your kind reply Mr. Walter Roberson.
I mean I need to get the optimal values of the two optimization variables b(1) and b(2). For the given example in Mathworks https://www.mathworks.com/help/optim/ug/fmincon.html
fun = @(x)100*(x(2)-x(1)^2)^2 + (1-x(1))^2;
x0 = [-1,2];
A = [1,2];
b = 1;
x = fmincon(fun,x0,A,b)
The output of fmincon:
x =
0.5022 0.2489
So these to values of X is the upper and lower limits??
How could this fun could modified obtain the optimal values of the two optimization variables?
Yes, but you did not think about what I wrote. The minimum value of that objective function occurs at
b(1)=0, b(2)=0
There is no need to even use an optimizer to find that point.
You could use fmincon however. It should give you approximately [0,0] (though not exactly so. This is a numerical solver.) Why not try it? Use the code that you wrote.
"So these to values of X is the upper and lower limits??"
No, x(1) of the output of fmincon is the first variable and x(2) of the output of fmincon is your second variable. Those are not ranges for variables and they are not ranges of function values: they are the location that minimized the function.
If you were to modify to
[x, fval] = fmincon(fun,x0,A,b)
then the function value at that optimal location would also be output.

Sign in to comment.

Tags

No tags entered yet.

Asked:

on 8 Feb 2018

Commented:

on 9 Feb 2018

Community Treasure Hunt

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

Start Hunting!