excel solver
optimization
simulation
Optimization Toolbox, MATLAB

   solver.com

Frontline Systems, Inc.  

quadratic programming, portfolio optimization, quadratic solver 
Developers of Your Spreadsheet's Solver  
robust optimization, stochastic programming, simulation optimization
   

Solver Platform SDK - MATLABŪ Optimization Toolbox API


optimization, solver, Excel

 
Home
Register
What's New
Solver Tutorial
Solver Technology
Select a Product
Excel Users
MATLAB Users
Developers
Government Users
Academic Users
Press/Analysts
Privacy Policy
 

 

 
This page illustrates how you can solve the following constrained nonlinear optimization problem:

Minimize
   x1*x1 + x2*x2
Subject to:
   x1 + x2 = 1
   x1 * x2 >= 0
   0 <= x1, x2 <= 1

using the Solver Platform SDK with its MATLAB Optimization Toolbox compatible API.  Click the links below to see example MATLAB code written using the SDK's other APIs.

bulletMATLAB Object-Oriented API
bulletMATLAB Procedural API

To solve a constrained nonlinear optimization problem using the Optimization Toolbox API, you must write two MATLAB functions -- one to compute values for the objective (we'll call this objfun), and one to compute values for the constraints (we'll call this confun) -- and then call the fmincon function, passing the addresses of these two functions as arguments.  Each MATLAB function is generally placed in a separate M-file.

This function computes a value for the objective, given current trial values for the problem variables as chosen by the optimizer:

function f = objfun(x)
   f = x(1) * x(1) + x(2) * x(2);
end

This function computes values for the constraints, given current trial values for the problem variables.  You must separate the constraints into inequalities (which we'll call c) and equalities (which we'll call ceq).  fmincon expects constraints of the form c <= 0 and ceq = 0.  Our first constraint is x1 + x2 = 1, so we'll have to subtract 1 to form (x1 + x2 - 1) = 0.  Our second constraint is x1 * x2 >= 0, so we must multiply by -1 to form -x1 * x2 <= 0.

function [c, ceq] = confun(x)
   ceq = [x(1) + x(2) - 1];
   c = [-x(1) * x(2)];
end

Below is the code to call fmincon, passing vectors for the lower and upper bounds on the variables, and the addresses of the two functions above.  You must pass the arguments in the correct order, and supply the empty matrix [] for the arguments you are not using.

function Example4
   lb = [0; 0];
   ub = [1; 1];
   x0 = [1; 1];
   [x,obj,exitflag] =
      fmincon(@objfun,x0,[],[],[],[],lb,ub,@confun,[]);
end

After calling fmincon, you must test the exitflag value to determine whether any error occurred.  If the optimization was successful, you can display or otherwise work with obj, the final value of the objective, and the vector x, the final values of the decision variables.

Back to MATLAB API Overview 

Back to MATLAB Users Start Here

To Learn More:
For instant access to example models, full-text User Guides, and to download free 15-day trial versions of our software products whenever you're ready, you can register now.
User Type
Email Address
Name First Last
Company University
Phone

Trial version passwords are sent to the above email address: See Privacy Policy.
Our Premium Solver Platform works with existing Excel Solver models, solves much larger problems up to hundreds of times faster, and solves new kinds of problems via Evolutionary Solver.  Solver Engines plug into the Premium Solver Platform.
   
Solver Platform SDK makes it easy to solve any type or size of optimization problem in your Visual Basic, VB.NET, C/C++, C#, Java, or MATLAB program. And it's easy to deploy your application with our flexible licensing for software vendors and corporate developers.
   
spreadsheet solver
scarce resources