fmincon optimization issue: maximize x by changing only some of the input variables

16 views (last 30 days)
I have data in excel which I am using to make an optimization analysis. In excel, using the solver, it's easy: I can choose a cell with a formula then pick the cells i need to change and add constraints and then minimize. But, I'm lost when it comes to Matlab's optimization process. The documentation appears to only provide examples of optimization problems that analyze simple one-line functions like f(x) = -(x1)(x2)(x3). I am unable to figure out how to apply these examples in my own case.
The function I am trying to maximize is relatively complex. As inputs, it takes on a number of scalar variables as well as multiple structures that contain data that is used in the calculations.
My issue is that I am trying to maximize the value of the function by altering three scalar variables, while leaving the other input variables constant (since they are data). More specifically, my function looks something like:
function x = NameOfFunction (w1, w2, w3, a, b, c, Structure1, Structure2)
I would like to maximize x by changing only variables w1, w2, and w3. In other words, I would like for Matlab to tell me the values of w1, w2, and w3 that maximize x, while leaving all the other variables alone. Any insight is greatly appreciated. I am trying to use fmincon.

Accepted Answer

Shashank Prasanna
Shashank Prasanna on 2 Jul 2013
What you are trying to do is easily achieved by using anonymous function and well explained in this documentation page:
In short you would change your objective function as follows:
>> f = @(w) NameOfFunction (w(1), w(2), w(3), a, b, c, Structure1, Structure2)
>> fmincon(f,w0,...)

More Answers (0)

Categories

Find more on Get Started with Optimization Toolbox 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!