---
title: Multivariable control and decoupling
heading: Plants with several inputs and outputs: the gain matrix, interaction and the relative gain array, pairing loops, static decoupling, and ill-conditioned plants
eyebrow: S9 · Lesson 46 · Multivariable control and decoupling
xp: 50
---

::: hook
A shower has two valves and two things you care about: how hot the water is and how much of it there is. Open the hot valve and both change. Adjust one to fix the temperature and the flow moves; fix the flow and the temperature drifts. Two people each minding one variable with one valve would fight each other. Most real plants are like this: a distillation column's compositions, a power converter's two outputs, an aircraft's pitch and speed. Multivariable control asks how strongly the loops interact, which input should control which output, and how to undo the coupling.
:::

::: play
- The curve is the relative gain $\lambda_{11} = 1/(1 - \kappa)$ of a 2 × 2 plant against its coupling $\kappa = k_{12}k_{21}/(k_{11}k_{22})$, the product of the cross gains over the product of the direct ones.
- With no coupling, κ = 0 and λ = 1: each loop behaves the same whether the other is open or closed.
- As κ approaches 1, λ blows up and the plant becomes nearly singular; for κ > 1, λ is negative and that pairing changes sign when the other loop closes.
:::

```sim plot
view: graph
x: k = -3..0.9
y: L = -2..10
plot: 1/(1 - k) | label: λ11 against coupling κ
plot: 1 + 0*k | dashed | label: no interaction
```

::: predict
## A shower mixes hot water at 60 °C and cold at 20 °C, half a kilogram per second of each. If one loop controls temperature with the hot valve and another controls flow with the cold valve, how much does each loop's effective gain change when the other loop closes?

- [ ] Not at all
- [ ] By 10%
- [x] It halves, or doubles depending on direction: the relative gain is 0.5
- [ ] The loops become independent

::: reveal
At this operating point the gain matrix from (hot, cold) to (flow, temperature) is $\begin{pmatrix} 1 & 1 \\ 20 & -20 \end{pmatrix}$ (in kg/s and °C per kg/s), so κ = (1 × 20)/(1 × (−20)) = −1 and λ = 1/(1 + 1) = 0.5. Every element of the relative gain array is 0.5: both pairings interact equally strongly, which is why a shower is easier with a mixing valve that separates flow from temperature.
:::
:::

::: nameit
## The gain matrix

A plant with inputs u and outputs y has a transfer matrix G(s), $y = G(s)u$. At steady state it's the gain matrix $K = G(0)$, with $k_{ij}$ the change in output i per unit of input j with the others held fixed.

## The relative gain array

Bristol's **relative gain** compares input j's effect on output i with the other loops open (the others' inputs held fixed) to its effect with them closed perfectly (the others' outputs held fixed):
$$\lambda_{ij} = \frac{k_{ij}}{\left(1/K^{-1}\right)_{ji}}, \qquad \Lambda = K \circ (K^{-1})^T$$
For a 2 × 2 plant, $\lambda_{11} = \lambda_{22} = \frac{1}{1 - \kappa}$ and $\lambda_{12} = \lambda_{21} = 1 - \lambda_{11}$; every row and column of Λ sums to 1. When the other loop closes, loop 1's effective gain becomes $k_{11}/\lambda_{11}$.

## Pairing

- Pair each output with the input whose relative gain is closest to 1: the loop then behaves about the same whatever the others do.
- Never pair on a negative relative gain: closing the other loops reverses that loop's gain, and with integral action it goes unstable.
- Large relative gains (above about 10) mean the plant is nearly singular: small model errors make large errors in the inverse, and decentralized control struggles.

## Decoupling

A static **decoupler** $D = K^{-1}$ in front of the plant makes the steady-state gain from the new inputs v to y the identity, $KD = I$, so single-loop controllers can act on v. For the shower it's hot = 0.5F + 0.025T, cold = 0.5F − 0.025T: adjust both valves together for flow, oppositely for temperature. Its accuracy depends on K's **condition number**, the ratio of largest to smallest singular value: an ill-conditioned K has a direction in which the plant barely responds, and its inverse amplifies any error in that direction.
:::

::: example
## Find the relative gain array of the shower at 0.5 kg/s each of 60 °C and 20 °C water, and its decoupler.

::: solution
1. **The model.**
   $$\begin{aligned} F &= h + c \\ T &= \frac{60h + 20c}{h + c} \end{aligned}$$
2. **Linearize.** At 0.5 kg/s each, T = 40 °C and
   $$\begin{aligned} \partial T/\partial h &= (60 - 40)/1 \\ &= 20 \\ \partial T/\partial c &= (20 - 40)/1 \\ &= -20 \end{aligned}$$
3. **Gain matrix.**
   $$K = \begin{pmatrix} 1 & 1 \\ 20 & -20 \end{pmatrix}$$
4. **Relative gains.**
   $$\begin{aligned} \kappa &= \frac{1 \times 20}{1 \times (-20)} \\ &= -1 \end{aligned}$$
   so every relative gain is 0.5.
5. **Decoupler.** With det K = −40:
   $$K^{-1} = \begin{pmatrix} 0.5 & 0.025 \\ 0.5 & -0.025 \end{pmatrix}$$
   It moves both valves equally for flow and in opposition for temperature.

**Answer:** every relative gain is 0.5, and the decoupler is $K^{-1}$ above.
:::
:::

::: example
## A plant has $K = \begin{pmatrix} 2 & 1.5 \\ 1 & 1 \end{pmatrix}$. Find $\lambda_{11}$, loop 1's effective gain with loop 2 closed, and K's condition number.

::: solution
1. **Interaction measure.**
   $$\begin{aligned} \kappa &= \frac{1.5 \times 1}{2 \times 1} \\ &= 0.75 \end{aligned}$$
2. **Relative gain.**
   $$\begin{aligned} \lambda_{11} &= 1/0.25 \\ &= 4 \end{aligned}$$
3. **Effective gain.** Closing loop 2 cuts loop 1's gain from 2 to
   $$2/4 = 0.5$$
4. **Condition number.** The singular values are 2.87 and 0.174, so
   $$\sigma_1/\sigma_2 = 16.4$$
5. **What it means.** The plant responds 16 times more weakly in one input direction than another, and a decoupler built from a slightly wrong K could amplify errors badly in that weak direction.

**Answer:** $\lambda_{11}$ = 4, loop 1's gain falls to 0.5 with loop 2 closed, and the condition number is 16.4.
:::
:::

::: example
## A plant has $K = \begin{pmatrix} 1 & 2 \\ 1 & 1 \end{pmatrix}$. Which pairing should be used?

::: solution
1. **Interaction measure.**
   $$\begin{aligned} \kappa &= \frac{2 \times 1}{1 \times 1} \\ &= 2 \end{aligned}$$
2. **Relative gains.**
   $$\begin{aligned} \lambda_{11} &= \frac{1}{1 - 2} \\ &= -1 \\ \lambda_{12} &= 2 \end{aligned}$$
3. **The diagonal pairing.** Pairing output 1 with input 1 would use a negative relative gain: closing the other loop flips that loop's sign, and integral action drives it unstable.
4. **The other pairing.** Pair output 1 with input 2 and output 2 with input 1 instead, whose relative gain of 2 is positive, though still far enough from 1 to show real interaction.

**Answer:** pair output 1 with input 2 and output 2 with input 1.
:::
:::

::: check
kind: parts
given: a = 1 | 2 | 5; d = 1 | 4; c = 0.5 | 2; k = -2 | -0.5 | 0.3 | 0.6 | 0.8; let b = k*a*d/c

## A 2 × 2 plant has gain matrix $K = \begin{pmatrix} \given{a} & \given{b} \\ \given{c} & \given{d} \end{pmatrix}$.

::: part
answer: 1/(1 - b*c/(a*d))
tolerance: 0.5%

### What is $\lambda_{11}$?

::: misses
- [any] $1/(1 - k_{12}k_{21}/(k_{11}k_{22}))$.
:::
:::

::: part
answer: 1 - 1/(1 - b*c/(a*d))
tolerance: 1%

### What is $\lambda_{12}$?

::: misses
- [any] Each row sums to 1.
:::
:::

::: part
answer: a - b*c/d
tolerance: 1%

### What is loop 1's gain when loop 2 holds its output perfectly?

::: misses
- [a] That's with loop 2 open.
- [any] $k_{11}/\lambda_{11} = k_{11} - k_{12}k_{21}/k_{22}$.
:::
:::
:::

::: check
kind: parts
given: H = 50 | 60 | 70; C = 10 | 20; h = 0.3 | 0.5; c = 0.5 | 0.7

## A shower mixes {h} kg/s of hot water at {H} °C with {c} kg/s of cold at {C} °C.

::: part
answer: (H*h + C*c)/(h + c)
unit: °C
tolerance: 0.5%

### What is the mixed temperature?

::: misses
- [any] The flow-weighted average.
:::
:::

::: part
answer: (H - (H*h + C*c)/(h + c))/(h + c)
tolerance: 0.5%

### How many °C does the temperature rise per extra kg/s of hot water?

::: misses
- [any] $\partial T/\partial h = (T_h - T)/(h + c)$.
:::
:::
:::

::: check
kind: parts
given: a = 1 | 2; b = 1 | 3; c = 5 | 20; d = -5 | -20

## A 2 × 2 plant has $K = \begin{pmatrix} \given{a} & \given{b} \\ \given{c} & \given{d} \end{pmatrix}$. A static decoupler $D = K^{-1}$ is placed ahead of it.

::: part
answer: d/(a*d - b*c)
tolerance: 0.5%

### What is $D_{11}$?

::: misses
- [1/a] The inverse mixes all four gains.
- [any] $k_{22}/\det K$.
:::
:::

::: part
answer: -b/(a*d - b*c)
tolerance: 0.5%

### What is $D_{12}$?

::: misses
- [any] $-k_{12}/\det K$.
:::
:::
:::

::: check
kind: parts
given: a = 1 | 2 | 4; b = 0.5 | 1.5; c = 0.5 | 1; d = 1 | 2

## Find the condition number of $K = \begin{pmatrix} \given{a} & \given{b} \\ \given{c} & \given{d} \end{pmatrix}$.

::: part
answer: sqrt((a^2 + b^2 + c^2 + d^2 + sqrt((a^2 + b^2 + c^2 + d^2)^2 - 4*(a*d - b*c)^2))/(a^2 + b^2 + c^2 + d^2 - sqrt((a^2 + b^2 + c^2 + d^2)^2 - 4*(a*d - b*c)^2)))
tolerance: 0.5%

### What is $\sigma_\max/\sigma_\min$?

::: misses
- [any] The squared singular values are the eigenvalues of $K^TK$: $\frac{t \pm \sqrt{t^2 - 4\det^2}}{2}$ with t the sum of squares.
:::
:::
:::

::: check
kind: parts
given: a = 1 | 2; d = 0.5 | 1; c = 0.5 | 2; k = 1.5 | 2 | 4; let b = k*a*d/c

## A plant has $K = \begin{pmatrix} \given{a} & \given{b} \\ \given{c} & \given{d} \end{pmatrix}$, with strong cross gains.

::: part
answer: 1/(1 - b*c/(a*d))
tolerance: 0.5%

### What is $\lambda_{11}$ for the diagonal pairing?

::: misses
- [any] $1/(1 - \kappa)$.
:::
:::

::: part
answer: 1 - 1/(1 - b*c/(a*d))
tolerance: 0.5%

### What is the relative gain of the off-diagonal pairing?

::: misses
- [any] $1 - \lambda_{11}$.
:::
:::
:::

::: check
kind: choice

## Why is pairing a loop on a negative relative gain dangerous?

- [ ] Negative gains can't be controlled
- [x] The loop's effective gain changes sign when the other loops close, so a controller tuned with the other loops open acts in the wrong direction once they're closed, and integral action then drives it unstable
- [ ] It makes the plant nonlinear
- [ ] It only matters for MIMO plants with more than two outputs

::: misses
- [1] A negative gain is fine if the controller's sign matches it.
- [3] The issue is linear.
- [4] It happens in any multivariable plant, 2 × 2 included.
:::
:::

::: check
kind: derivation
vars: a = 0.5..10, b = 0.1..10, c = 0.1..10, d = 0.5..10

## A 2 × 2 gain matrix with entries a, b (first row) and c, d (second row).

::: step
answer: b*c/(a*d)

### What is κ?
:::

::: step
answer: a*d/(a*d - b*c)

### What is $\lambda_{11}$?
:::

::: step
answer: a - b*c/d

### What is loop 1's gain with loop 2 closed perfectly?
:::

::: right
Right. The relative gain is the ratio of open-loop to closed-loop gain, $k_{11}$ over $k_{11} - k_{12}k_{21}/k_{22}$.
:::
:::

::: check
kind: python

## Write `inverse(K)` for a square list-of-lists matrix (Gauss–Jordan with partial pivoting) and `rga(K)`: the relative gain array $K \circ (K^{-1})^T$.

```python starter
def inverse(K):
    return K

def rga(K):
    return [[1.0 if i == j else 0.0 for j in range(len(K))] for i in range(len(K))]
```

```python solution
def inverse(K):
    n = len(K)
    M = [list(map(float, row)) + [1.0 if i == j else 0.0 for j in range(n)] for i, row in enumerate(K)]
    for i in range(n):
        p = max(range(i, n), key=lambda r: abs(M[r][i]))
        M[i], M[p] = M[p], M[i]
        piv = M[i][i]
        M[i] = [v / piv for v in M[i]]
        for r in range(n):
            if r != i:
                f = M[r][i]
                M[r] = [a - f * b for a, b in zip(M[r], M[i])]
    return [row[n:] for row in M]

def rga(K):
    Ki = inverse(K)
    n = len(K)
    return [[K[i][j] * Ki[j][i] for j in range(n)] for i in range(n)]
```

```python tests
L = rga([[1, 1], [20, -20]])
assert all(abs(L[i][j] - 0.5) < 1e-12 for i in range(2) for j in range(2)), "The shower: every relative gain is 0.5."
assert abs(rga([[2, 1.5], [1, 1]])[0][0] - 4) < 1e-12, "κ = 0.75 gives λ = 4."
K3 = [[1.0, 0.2, 0.1], [0.3, 2.0, 0.4], [0.1, 0.5, 1.5]]
L3 = rga(K3)
assert all(abs(sum(row) - 1) < 1e-12 for row in L3) and all(abs(sum(L3[i][j] for i in range(3)) - 1) < 1e-12 for j in range(3)), "Rows and columns sum to 1."
```

::: right
Right. The relative gain array is independent of how inputs and outputs are scaled, which is why it's a fair test of interaction.
:::
:::

::: explain
## What does a relative gain close to 1, or far from it, tell an engineer about decentralized control of a multivariable plant?

::: model
A relative gain compares how strongly an input moves its paired output when the other loops are open with how strongly it does when the other loops hold their outputs fixed. A value close to 1 means closing the other loops barely changes this loop's gain, so the loops can be tuned one at a time and work together as designed. Values far above 1 mean the other loops largely cancel this input's effect, a sign the plant is close to singular and sensitive to model errors. Negative values mean the effective gain flips sign when the others close, which makes that pairing unworkable. When no pairing gives relative gains near 1, a decoupler or a fully multivariable design is needed.
:::
:::

::: practice
::: check
given: a = 1 | 3; b = 0.5 | 1.5; c = 0.5 | 1; d = 2 | 4
answer: 1/(1 - b*c/(a*d))
tolerance: 0.5%

## $\lambda_{11}$ for K = [[{a}, {b}], [{c}, {d}]]?

::: misses
- [any] $1/(1 - k_{12}k_{21}/(k_{11}k_{22}))$.
:::
:::

::: check
given: a = 2 | 5; b = 1 | 2; c = 1 | 3; d = 2 | 6
answer: a - b*c/d
tolerance: 0.5%

## Loop 1's closed-loop-2 gain for K = [[{a}, {b}], [{c}, {d}]]?

::: misses
- [any] $k_{11} - k_{12}k_{21}/k_{22}$.
:::
:::

::: check
given: k = -2 | 0.5 | 0.8
answer: 1/(1 - k)
tolerance: 0.5%

## $\lambda_{11}$ for coupling κ = {k}?

::: misses
- [any] $1/(1 - \kappa)$.
:::
:::
:::
