I need to maximize the equation 3x+y in matlab with the following constraints:
2x+y<=6, x+3y<=9, and x,y>=0
I am having a really hard time figuring out
As @Franck mentioned, you can in general use fmincon to solve optimization problems. However, as your problem is simply a linear programming problem, the solution is much simpler (and guaranteed to be optimal) :
f = -[3 1]; % Note the minus as we want maximization
A = [2 1; 1 3];
b = [6; 9];
LB = [0 0];
[X, FVAL] = linprog(f,A,b,[],[],LB)
Will give:
X =
3.0000
0.0000
FVAL =
-9.0000
Hence the optimum is found at point (3,0) and the resulting value is 9.
Try help linprog to read more about this very usefull function.