How to solve an optimization problem with an objective function which is not directly a function of decision variables?

6 views (last 30 days)
My objective function and constraints include some expressions each of which are defined separately. Therefore the OF and constraints does not directly include variables. I know that the optimization functions in Matlab require the variables to present in the constraints or OFs to be able to solve the problem. I cannot bring variables to my functions because I do max operation and some different for loops for their calculations separately.
  4 Comments
Bahar Bahari
Bahar Bahari on 15 Dec 2019
Edited: Walter Roberson on 7 Oct 2020
Hello
I have the same question in using GA but I found the answer a bit complicated. Could you say the soloution for a simple question as follows:
a=10;
b=5;
x=2a+b
y=b/3
z=x+y
I want to minimize "z" while "a" & "b" are the variables.
Thank you very much.

Sign in to comment.

Accepted Answer

Alan Weiss
Alan Weiss on 18 Mar 2014
I am not sure that I understand you. If you have some parameters that are not decision variables, but instead are extra parameters or data, see how to pass extra parameters.
If you have some parameters that depend on intermediate calculations in your objective or nonlinear constraint functions, then just wratp them into your function files.
If I misunderstand you completely, please try again, and perhaps include a bit of pseudocode so that we can have a better chance of understanding your situation.
Alan Weiss
MATLAB mathematical toolbox documentation
  3 Comments
Alan Weiss
Alan Weiss on 19 Mar 2014
Thanks for the explanation. Here is how I would approach this problem.
  1. Get the Excel data into your workspace first with the xlsread statement.
  2. Create the parameters I, J, K, and whatever else you need that doesn't depend on anything but the data.
  3. Write a function file OF = myfunction(x,I,J,K,...), where x represents ALL your decision variables, and I,J,K,... are ALL your parameters that you need. myfunction should return the value of the objective function when x,I,J,K,.. are specified.
  4. Call the solver like this:
[solution,value] = patternsearch(@(x)myfunction(x,I,J,K,...),x0)
or
[solution,value] = ga(@(x)myfunction(x,I,J,K,...),numVariablesInx)
Alan Weiss
MATLAB mathematical toolbox documentation

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!