Skip to main content

Using KNITRO with MATLAB

Overview

KNITRO® is a solver for nonlinear optimization from Ziena Optimization Inc. It is a library of routines that can be called from MATLAB using the knitromatlab external interface function.

MATLAB is configured to use KNITRO when it starts up. Do not set the system path to include the KNITRO libraries. That is done for you.

Getting Started

Now you're ready to run an example that's designed to be modified for your own use.

Example

Ziena provides examples that illustrate how to call KNITRO from a MATLAB application. An issue with the current KNITRO release is that it won't work with the MATLAB graphical desktop, so this procedure works around that problem.

Start an interactive, non-desktop MATLAB session: matlab -nosplash -nodisplay -nodesktop

Once MATLAB is ready, change to the KNITRO MATLAB installation directory: cd /opt/knitro/knitromatlab

The file README contains descriptions of all of the example files in this directory.

Review the README file to learn about the examples: ! more   README

Be sure to type ! at the beginning of that line. That escapes MATLAB to the operating system to run the more program to display the README file. It pauses when the screen is filled. Press the Space bar to continue to the next screen, press q to quit and return to MATLAB.

The file exampleLP1.m calls KNITRO's MEX interface. It demonstrates how to formulate a linear program in MATLAB and calls knitromatlab to solve the LP model.

To run it, just type exampleLP1 at MATLAB's >> prompt.

The file knitro.opt is a sample KNITRO input file of user options. Copy that file, and modify it using any text editor.

Now you can copy the example and user option files to fit your own models.

Last Updated: 24 January 2017

Get Help Back to top