File Exchange

image thumbnail

Learning PID Tuning III: Performance Index Optimization

version (41.6 KB) by Yi Cao

Yi Cao (view profile)

A tool and tutorial to perform optimal PID tuning


Updated 11 Feb 2008

View License

Most PID tuning rules are based on first-order plus time delay assumption of the plant hence cannot ensure the best control performance. Using mordern optimization techniques, it is possible to tune a PID controller based on the actual transfer function of the plant to optimize the closed-loop performance.

This submission contains a function to perform optimal PID design based on four different performance indices, e.g. the ISE, the IAE, the ITSE and the ITAE. A published m-file provides two 4th-order examples to explain the usage and to show impact of using different performance indices.

The example file requires the znpidtuning function, which can be downloaded from

Comments and Ratings (9)

Jagan kumar M

How to run this file. I got error like below.

Warning: Escape sequence '\U' is not valid. See 'help sprintf' for valid escape sequences.
> In DynamicSystem.margin at 48
In optimPID at 52
In optimalpidtuning at 44
Error using DynamicSystem/margin (line 48)
Error: optimPID (line 52)

Error in optimalpidtuning (line 44)
C1=optimPID(G,3,1); % PID-Control, ISE index

please help me i am new to matlab


Manoj (view profile)


Maria (view profile)

I tried using the optimPID function for a second-order system but I get the following error message: 'Error using fminusub (line 17)
Objective function is undefined at initial point. Fminunc cannot
Any help would be greatly appreciated.
Thank you.

Roberto Lopez

We have tried this powerful tool at a University in Ecuador, where I come from. We would like to include the code applied for the Transfer Function of our Engineering Graduation Project, respecting all what says in the licensing file. But we also would like to know if there is more information behind the "optimPID" function development, so we can also include it as a reference.
Thank you very much!

Roberto Lopez

robert howrd

Why your program hangs when I do this?

EDU>> clear all
EDU>> s=tf('s');
EDU>> sys=1/(10*s^2+s+1);
EDU>> sys2=optimPID(sys,1,1)

it now hangs. I am using Matlab 2011a


Thanks for an interesting submission. If you are interested in designing and tuning PID controllers in MATLAB and Simulink, please take a look at new PID tuning capabilities shipped in Simulink Control Design in R2009b:

There is also a webinar on the subject:

and MATLAB Digest article:

V. Poor


MATLAB Release Compatibility
Created with R2007b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Discover Live Editor

Create scripts with code, output, and formatted text in a single executable document.

Learn About Live Editor