fmincon in a loop to get isovalue matrix

1 view (last 30 days)
James Choi
James Choi on 12 Feb 2016
Commented: Rena Berman on 24 Jan 2017
Hello, first of all I'm very sorry because of my poor english.
I have tried to solve a optimization problem with fmincon in Matlab.
Actually I already calculated result I wish with ms excel and "SOLVER".
It was relatively so easy compared to Matlab.
I uploaded zipped file which has excel(problem_optimization2.xlsx)
and Matlab files(example.m, confun.m, VF.mat).
My purpose is that every single element in a result matrix has same value.
(From excel's result, it is about 62.4)
x : 5x5 matrix, should be optimized
VF : 5x5x5x5 4-Dimensional matrix, calculated another function
mysum : 5x5 result matrix, sum(x(i,j) * VF(:,:,i,j))
objective : max(max(mysum))-min(min(mysum)) = 0 constraints : MIN(x) >= 0, SUM(x) = 2500
. .
I'm newbie for Matalb, but I found out that I have to use fmincon in a for loop because of x and VF have i,j elements. I wrote the matlab code but It's not working properly now.
How can I use fmincon in a for loop to optimize input matrix x? And please let me know wrong expressions I wrote.
Thank you for any suggestions in advance.

Answers (2)

Walter Roberson
Walter Roberson on 12 Feb 2016
If you have 25 values and SUM(x) = 2500 and all of the values need to be the same, then the only solution is that the values should each be 2500/(5*5) which is to say 100.
  2 Comments
James Choi
James Choi on 12 Feb 2016
MIN(x) >= 0 and SUM(x) = 2500 is constaint function. My objective is to minimize max(mysum)-min(mysum).
Walter Roberson
Walter Roberson on 12 Feb 2016
SUM(x) = 2500 is an equality constraint. Any solution that does not have x sum to exactly 2500 is to be rejected. And you want all of the values to be the same in the matrix, so the solution is that each element should be 2500 divided by the number of elements. That would clearly give the maximum and minimum the same. The number of elements is positive so each of the entries (that are exactly the same) would be greater than 0. This solution meets your constraints and can be calculated directly without any minimization.

Sign in to comment.


James Choi
James Choi on 12 Feb 2016
I solved this problem with writing additional m file which has for loop. Runnig script file call additional m file so I manage to run fmincon in a for loop. Thanks.

Community Treasure Hunt

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

Start Hunting!