ZPK
The zero-pole-gain (ZPK) format is an alternative way to represent a transfer function. Instead of specifying the coefficients of the numerator and denominator polynomials, the ZPK format defines the locations of the roots of those equations in the complex plane.
The transfer function is defined as:
H(s) = k \frac{(s - z_1)(s - z_2)\dots(s - z_m)}{(s - p_1)(s - p_2)\dots(s - p_n)}
Where z_i are the system zeros, p_j are the system poles, and k is the system gain. Zeros are values of s where the transfer function goes to zero, while poles are values where it goes to infinity.
Excel Usage
=ZPK(zeros, poles, gain)
zeros(list[list], required): Array containing the locations of the system zeros.poles(list[list], required): Array containing the locations of the system poles.gain(float, required): The system gain (k).
Returns (str): String representation of the TransferFunction object with ZPK format.
Example 1: Single zero and pole
Inputs:
| zeros | poles | gain | |
|---|---|---|---|
| 1 | 2 | 3 | 1 |
Excel formula:
=ZPK({1}, {2,3}, 1)
Expected output:
"<TransferFunction>: sys[0]\nInputs (1): ['u[0]']\nOutputs (1): ['y[0]']\n\n s - 1\n -------------\n s^2 - 5 s + 6"
Example 2: No zeros (all-pole system)
Inputs:
| zeros | poles | gain | |
|---|---|---|---|
| -1 | -2 | 5 |
Excel formula:
=ZPK({""}, {-1,-2}, 5)
Expected output:
"<TransferFunction>: sys[1]\nInputs (1): ['u[0]']\nOutputs (1): ['y[0]']\n\n 5\n -------------\n s^2 + 3 s + 2"
Example 3: Complex conjugate poles (approximated conceptually as we pass floats in test cases usually)
Inputs:
| zeros | poles | gain | |
|---|---|---|---|
| -5 | -1 | 1 | 2 |
Excel formula:
=ZPK({-5}, {-1,1}, 2)
Expected output:
"<TransferFunction>: sys[2]\nInputs (1): ['u[0]']\nOutputs (1): ['y[0]']\n\n 2 s + 10\n --------\n s^2 - 1"
Example 4: Integrator pole at origin
Inputs:
| zeros | poles | gain |
|---|---|---|
| 0 | 1 |
Excel formula:
=ZPK({""}, {0}, 1)
Expected output:
"<TransferFunction>: sys[3]\nInputs (1): ['u[0]']\nOutputs (1): ['y[0]']\n\n 1\n -\n s"
Python Code
Show Code
import control as ct
import numpy as np
def zpk(zeros, poles, gain):
"""
Create a transfer function model from zeros, poles, and gain.
See: https://python-control.readthedocs.io/en/latest/generated/control.zpk.html
This example function is provided as-is without any representation of accuracy.
Args:
zeros (list[list]): Array containing the locations of the system zeros.
poles (list[list]): Array containing the locations of the system poles.
gain (float): The system gain (k).
Returns:
str: String representation of the TransferFunction object with ZPK format.
"""
try:
def parse_numeric_value(value):
if isinstance(value, complex):
return value
if isinstance(value, (int, float)):
return float(value)
if isinstance(value, str):
text = value.strip()
if text == "":
return None
try:
return float(text)
except ValueError:
return complex(text)
return complex(value)
def flatten_to_1d(x):
if not isinstance(x, list):
parsed = parse_numeric_value(x)
return [] if parsed is None else [parsed]
flat = []
for row in x:
if isinstance(row, list):
for val in row:
parsed = parse_numeric_value(val)
if parsed is not None:
flat.append(parsed)
else:
parsed = parse_numeric_value(row)
if parsed is not None:
flat.append(parsed)
return flat
z_arr = flatten_to_1d(zeros)
p_arr = flatten_to_1d(poles)
k = float(gain)
sys = ct.zpk(z_arr, p_arr, k)
return str(sys)
except Exception as e:
return f"Error: {str(e)}"