Install any skill in seconds. Free to start, no credit card required.
Get Started Free →matlab/matlab-solve-optimization
Use when writing, solving, or debugging MATLAB optimization code — formulating problems (optimproblem, optimvar, fcn2optimexpr), selecting and configuring solvers (fmincon, linprog, quadprog, intlinprog, lsqnonlin, ga, surrogateopt, optimoptions), or validating results (exitflag, convergence, constraint violations). Covers problem-based and solver-based approaches, solver tuning, and solution verification.
Passed 21 of 22 test cases with the skill, and 17 of 22 without it.
and 4 more in the full report
5 fixed16 passed either way0 still failing1 broke
Tokens, turns and time describe resource use, not a dollar price.
One of 5 test cases the skill fixed. Same model, same prompt, with and without the skill.
I'm working on a facility location problem in MATLAB where some decision variables are binary and others represent continuous allocation amounts, with budget and capacity constraints. Could you give me MATLAB code to set up this problem, pick the right solver, set up solver options safely, and analyze the solution after solving? I want the script to check constraint satisfaction and demonstrate how to handle cases where the solver doesn't reach convergence.
| Checked | Without skill | With skill |
|---|---|---|
| The MATLAB script constructs the optimization model using optimproblem. | Passed | Passed |
| The initial guess supplied to solve is formatted as a MATLAB struct. | Missed | Passed |
| The post-solve check uses issatisfied on the problem and solution. | Missed | Passed |
The instructions your model reads when the skill loads.
Guide the full optimization lifecycle: classify the problem, formulate it, select and configure a solver, and validate the results.
optimproblem, optimvar, optimconstr, optimexpr, or fcn2optimexproptimoptions, algorithm choice, tuning)solve(eqns, vars), ODE systems, or linear system solves (A\b)Before formulating, identify the problem class — it determines which solver to use, what guarantee you can promise (global vs local), and whether a domain-specific tool should replace the generic path.
See references/classify.md for the class→solver→guarantee table, convexity quick-checks, and "hidden easier class" heuristics. Key actions:
optimproblemeig(H) — nonconvex QPs cannot use quadprog reliablymax, min, abs, sort, if/branching, or norms other than squared-2-normUse problem-based by default for readable definitions, N-D modeling, and every LP, QP, conic, and mixed-integer problem (unless coefficients are already in matrix-vector form). Problem-based provides automatic differentiation and is less error-prone.
Even when AD is blocked (e.g., ode45 in the objective), fcn2optimexpr can still wrap the function as a black-box — problem-based remains useful.
test cases passed, vs 17 / 22 without
More skills from the same source and nearby in the registry, with their headline benchmark lift.