Installing PSOPT on Ubuntu 22.04 for Optimal Control Applications

PSOPT is an open-source toolbox designed for solving optimal control problems within the MATLAB environment, commonly used in aerospace trajectory optimization, robotic motion planning, and automated system design. This guide walks through the complete installation process on Ubuntu 22.04, ensuring seamless integration with MATLAB.

Prerequisites

Before proceeding, verify that your system meets the following requirements:

  • Ubuntu 22.04 LTS (64-bit)
  • MATLAB R2020b or later, properly installed and licensed
  • Access to root privileges for system-level installations

Install System Dependencies

Begin by updating the package index and enstalling essential build tools and libraries:

sudo apt update
sudo apt install -y build-essential cmake git liblapack-dev libblas-dev

Install the MATLAB support package to enable system-level integration:

sudo apt install -y matlab-support

Configure MATLAB Python Engine (Optional)

If you intend to invoke MATLAB functions from Python scripts, install the MATLAB Engine API for Python. Navigate to the MATLAB installation directory and run the setup script:

cd /usr/local/MATLAB/R2020b/extern/engines/python
sudo python3 setup.py install

Alternatively, install via pip if the above fails:

pip3 install matlabengineforpython

Download and Compile PSOPT

Clone the official PSOPT repository from GitHub:

git clone https://github.com/PSOPT/psopt.git
cd psopt

Create a dedicated build directory and configure the project using CMake:

mkdir build && cd build
cmake -DMATLAB_ROOT=/usr/local/MATLAB/R2020b ..

Replace /usr/local/MATLAB/R2020b with your actual MATLAB installation path if different. If CMake reports missing dependencies, ensure libmex.so and libmx.so are accessible in the MATLAB lib directory.

Compile and install the library:

make -j$(nproc)
sudo make install

Integrate PSOPT with MATLAB

Launch MATLAB and add the PSOPT MATLAB interface to the path:

addpath('/usr/local/psopt/matlab');
savepath

Confirm the path is correct by checking the installation directory:

ls /usr/local/psopt/matlab

Run the built-in example to validate the installation:

example_psopt

If successful, MATLAB will display a solved optimal control problem with plots of state and control trajectories.

Troubleshooting

Issue: CMake cannot locate MATLAB
Ensure the MATLAB_ROOT variable points to the correct installation root. Use which matlab to confirm the executable location, then trace back to the installation directory.

Issue: Missing mex files during compilation
Verify that the MATLAB MEX compiler is available by running mex -setup in MATLAB. Install the required compiler (e.g., GCC) if prompted.

Issue: Python engine fails to load
Check Python version compatibility. MATLAB R2020b requires Python 3.7 or 3.8. Use python3 --version and reinstall the engine if mismatched.

Issue: Permission denied during install
Insure the target directory (/usr/local/psopt) is writable. Use sudo chown -R $USER:$USER /usr/local/psopt if needed.

Tags: PSOPT OptimalControl MATLAB CMake ubuntu22.04

Posted on Tue, 19 May 2026 22:32:59 +0000 by ghettopixel