# Optimization function based on different domain of optimized variables

1 view (last 30 days)
vanguard478 on 26 Nov 2020
Commented: vanguard478 on 26 Nov 2020
Hello,
I have an linear objective function f(x1,x2,x3.. ) which is defined for a fixed domain of x1 say x1< (constant k). Also the objective function changes to g(x1,x2,x3 ... ) if x1> (constant k). The objective function in both the cases is linear. x1,x2,x3 are the optimization variables. There are set of other equality and inquality constraints on the other variables.
I was trying to solve this optimization problem using linprog .
How can I switch the optimization function based on the domain of x1? Can I iterate over the current value of x1 and check if it is less than that constant in 'linprog' solver and accordingly select the optimization function f or g?

Matt J on 26 Nov 2020
Edited: Matt J on 26 Nov 2020
Solve the problem twice, once with the constraint x1<=k and once with x1>=k, imposing the appropriate objective function in each case. Whichever of the solutions gives the best objective function value wins.

#### 1 Comment

vanguard478 on 26 Nov 2020
Okay.. Thank you for the reply.
I asked this because I was just wondering if there was any other more succint way of doing this instead of writing the same constraints x2,x,3...etc ( which don't affect the objective functions ,being the same for both f and g) as many times as the different domains of the constraint x1 specified.

R2019a

### Community Treasure Hunt

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

Start Hunting!