Optimization of a linear function with range of variables

I have a simple optimization problem. The objective function consists of 4 variables, say a,b,c and d. so objective function y=f(a,b,c,d). y is a linear function.
and constraints for this variables are only range for that variable say a= 3 to 10, b= 25 to 35, c= 80 to 100 and d = 30 to 45. My question is which optimization technique/method/function i can use to get maximum value of 'y' in MATLAB. and how to plot all this variables in MATLAB to get 'y'

 Accepted Answer

You can solve this kind of problem numerically using the linprog function in Optimization Toolbox.
You can solve this kind of problem symbolically using the solve function in Symbolic Math Toolbox.
Alan Weiss
MATLAB mathematical toolbox documentation

3 Comments

Thank you very much for your quick response. i was trying to use 'linprog' but following error message i am getting ??? Error using ==> linprog at 131 LINPROG only accepts inputs of data type double.
my command was 'y=linprog(@objfun,[],[],[],[],lb,ub)' objective function is defind as function COP= objfun(Te,Ta,Tg,Tc) COP=(Tg-Ta)/Tg+Te/(Tc-Te); end . I do not have bound for my objective function. but have bounds for variables.Bound were specified for the variables Te,Ta,Tg,Tc as lb=[3 25 70 30] ub=[10 35 100 40]. I don't have any equality or inequality constraints.
You have several errors in your objective function. Please take a look at the documented linprog syntax. Or don't bother, because linprog will not work for this function anyway.
This is not a linear function. Several variables divide others.
Even using fmincon, the nonlinear constrained solver, you need to put all your variables in one vector, typically called x. Then you can do something like
function f = objfun(x)
Te = x(1);
Ta = x(2);
Tg = x(3);
Tc = x(4);
f = (Tg-Ta)/Tg + Te/(Tc-Te);
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
Got it Sir.... Thank you very much. I should have read the documentation carefully.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!