# MATLAB: Solve as Optimization Problem in Matlab

fminconfminunclinprogMATLABoptimization

I want to solve this simple equation as an optimization problem in Matlab. I have tried linprog, fmincon and fminunc and all do not seem to get it done. It is trivial to solve with brute-force in a loop (as below) and with Excel's Solver, but I want to be able to use one of Matlab's optimization routines too.
Solve:
15*i + 16*j + 17*k = 121
i, j and k are integers.
With loops, the solution is trivial:
for i = 0:100    for j = 0:100        for k = 0:100            val = 15*i + 16*j + 17*k;            if val == 121                disp('here!')                i,j,k            end        end    endend
The solution is i=7, j=1, k=0.
I want to solve as:
min 121 – 15*i – 16*j – 17*k
s.t. i,j,k are >=0 integers.
What is the appropriate formulation as a optimization problem in Matlab?
Thanks!

f = @(x) 121 - 15*x(1) - 16*x(2) - 17*x(3);sol = ga(@(x) f(x).^2, 3, [], [], [], [], [0 0 0], [], [], 1:3);
>> solsol =     7     1     0