# MATLAB API examples¶

This section lists a few examples in MATLAB. These are the same files that can be found in the examples directory of the distribution.

## Example 1: First steps¶

FirstExample.m

This example shows how to

• reassign values to parameters
• solve the model
• display the objective function value

## Example 2: Execute arbitrary statements¶

ExampleInterpreting.m

This example shows how to:

• interpret arbitrary AMPL Statements from MATLAB
• get the MATLAB representation of the underlying AMPL algebraic entities

## Example 3: Passing data¶

DataFrameExample.m

This example shows how to:

• use the dataframe object to communicate data between MATLAB and AMPL

## Example 4: Assign data to a model and solve it¶

DietModel.m

This example shows how to:

• read an AMPL model (diet model from the AMPL book)
• assign all the needed data from the API, using various forms of communication

## Example 5: Compound sets¶

CompoundSet.m

This example shows how to operate with compound sets

## Example 6: Simple heuristic¶

TrackingModel.m

This example shows how to:

• implement a simple heuristic to speed up the solution of a QMIP problem
• set AMPL options from the API

## Example 7: Efficient frontier¶

EfficientFrontier.m

This example shows how to:

• build an efficient frontier by repeteatly solve a portfolio problem in AMPL
• plot the resulting frontier

## Example 8: Redirecting AMPL Output¶

This example shows how to:

• Redirect the output of the AMPL interpreter to a user defined function