Assume that we have our discrete state space model:
A =
0.64376 0.58414
-0.58414 0.41451
B =
-1.43086
-0.86908
C =
-1.43086 0.86908
D = 0
delay = 0
sampleTime = 0.49749
Then we want to find the predicted values.
$$\Phi = \begin{bmatrix} CA\\ CA^2\\ CA^3\\ \vdots \\ CA^{N_p} \end{bmatrix} , \Gamma = \begin{bmatrix} CB &0 &0 &\cdots & 0\\ CAB & CB & 0 & \cdots & 0\\ CA^2B& CAB & 0 &\cdots &0 \\ \vdots & \vdots & \vdots & \vdots &\vdots \\ CA^{N_p-1}B & CA^{N_p-2}B & CA^{N_p-3}B & \cdots & CA^{N_p-N_c}B \end{bmatrix}$$
Where $N_p$ is prediction horizon and $N_c$ is the control horizon. Control horizon should always be lower than the prediction horizon. Always, else the computer will give you an error as input signal.
Anyway! We want to solve for this:
$$U = (\Gamma ^T \Gamma + a)^{-1}\Gamma ^T(Rr-\Phi x)$$ Where $R$ is our ones-vector and the $r$ is our reference scalar. The vector $x$ is our current state vector. The variable $a$ is just a very smal value so it's possible to invert. Else I recommend to use this:
$$U = \Gamma^{\dagger}(Rr-\Phi x)$$ Taking the pseudo inverse is much more safe method if the pesudo inverse is done by Singular Value Decomposition:
$$\Gamma = USV^T$$ $$\Gamma^{\dagger} = VS^{-1}U^T$$
Here is MATLAB/Octave code for computing $\Phi$ and $\Gamma$
function [PHI] = PHImatrix(C, A, Np)
PHI = [];
for i = 1:(Np)
PHI = [PHI; C*A^i];
endfor
endfunction
function [GAMMA] = GAMMAmatrix(C, A, B, Np, Nc)
PHI = [];
GAMMA = [];
for j = 1:Nc
for i = (1-j):(Np-j)
if i < 0
PHI = [PHI; 0*C*A^i*B];
else
PHI = [PHI; C*A^i*B];
endif
endfor
% Add to PHI
GAMMA = [GAMMA PHI];
% Clear F
PHI = [];
endfor
endfunction
If I set $N_p = 20$ and $N_c = 19$ I get this:
PHI =
-1.4288e+00 -4.7558e-01
-6.4199e-01 -1.0317e+00
1.8939e-01 -8.0267e-01
5.9079e-01 -2.2208e-01
5.1005e-01 2.5305e-01
1.8053e-01 4.0283e-01
-1.1909e-01 2.7243e-01
-2.3580e-01 4.3360e-02
-1.7713e-01 -1.1977e-01
-4.4066e-02 -1.5311e-01
6.1070e-02 -8.9206e-02
9.1423e-02 -1.3032e-03
5.9615e-02 5.2863e-02
7.4983e-03 5.6735e-02
-2.8314e-02 2.7897e-02
-3.4523e-02 -4.9758e-03
-1.9318e-02 -2.2229e-02
5.4858e-04 -2.0498e-02
1.2327e-02 -8.1762e-03
1.2712e-02 3.8115e-03
GAMMA =
Columns 1 through 13:
1.29207 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000
2.45772 1.29207 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000
1.81526 2.45772 1.29207 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000
0.42659 1.81526 2.45772 1.29207 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000
-0.65234 0.42659 1.81526 2.45772 1.29207 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000
-0.94974 -0.65234 0.42659 1.81526 2.45772 1.29207 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000
-0.60841 -0.94974 -0.65234 0.42659 1.81526 2.45772 1.29207 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000
-0.06636 -0.60841 -0.94974 -0.65234 0.42659 1.81526 2.45772 1.29207 0.00000 0.00000 0.00000 0.00000 0.00000
0.29972 -0.06636 -0.60841 -0.94974 -0.65234 0.42659 1.81526 2.45772 1.29207 0.00000 0.00000 0.00000 0.00000
0.35753 0.29972 -0.06636 -0.60841 -0.94974 -0.65234 0.42659 1.81526 2.45772 1.29207 0.00000 0.00000 0.00000
0.19612 0.35753 0.29972 -0.06636 -0.60841 -0.94974 -0.65234 0.42659 1.81526 2.45772 1.29207 0.00000 0.00000
-0.00986 0.19612 0.35753 0.29972 -0.06636 -0.60841 -0.94974 -0.65234 0.42659 1.81526 2.45772 1.29207 0.00000
-0.12968 -0.00986 0.19612 0.35753 0.29972 -0.06636 -0.60841 -0.94974 -0.65234 0.42659 1.81526 2.45772 1.29207
-0.13124 -0.12968 -0.00986 0.19612 0.35753 0.29972 -0.06636 -0.60841 -0.94974 -0.65234 0.42659 1.81526 2.45772
-0.06004 -0.13124 -0.12968 -0.00986 0.19612 0.35753 0.29972 -0.06636 -0.60841 -0.94974 -0.65234 0.42659 1.81526
0.01627 -0.06004 -0.13124 -0.12968 -0.00986 0.19612 0.35753 0.29972 -0.06636 -0.60841 -0.94974 -0.65234 0.42659
0.05372 0.01627 -0.06004 -0.13124 -0.12968 -0.00986 0.19612 0.35753 0.29972 -0.06636 -0.60841 -0.94974 -0.65234
0.04696 0.05372 0.01627 -0.06004 -0.13124 -0.12968 -0.00986 0.19612 0.35753 0.29972 -0.06636 -0.60841 -0.94974
0.01703 0.04696 0.05372 0.01627 -0.06004 -0.13124 -0.12968 -0.00986 0.19612 0.35753 0.29972 -0.06636 -0.60841
-0.01053 0.01703 0.04696 0.05372 0.01627 -0.06004 -0.13124 -0.12968 -0.00986 0.19612 0.35753 0.29972 -0.06636
Columns 14 through 19:
0.00000 0.00000 0.00000 0.00000 0.00000 0.00000
0.00000 0.00000 0.00000 0.00000 0.00000 0.00000
0.00000 0.00000 0.00000 0.00000 0.00000 0.00000
0.00000 0.00000 0.00000 0.00000 0.00000 0.00000
0.00000 0.00000 0.00000 0.00000 0.00000 0.00000
0.00000 0.00000 0.00000 0.00000 0.00000 0.00000
0.00000 0.00000 0.00000 0.00000 0.00000 0.00000
0.00000 0.00000 0.00000 0.00000 0.00000 0.00000
0.00000 0.00000 0.00000 0.00000 0.00000 0.00000
0.00000 0.00000 0.00000 0.00000 0.00000 0.00000
0.00000 0.00000 0.00000 0.00000 0.00000 0.00000
0.00000 0.00000 0.00000 0.00000 0.00000 0.00000
0.00000 0.00000 0.00000 0.00000 0.00000 0.00000
1.29207 0.00000 0.00000 0.00000 0.00000 0.00000
2.45772 1.29207 0.00000 0.00000 0.00000 0.00000
1.81526 2.45772 1.29207 0.00000 0.00000 0.00000
0.42659 1.81526 2.45772 1.29207 0.00000 0.00000
-0.65234 0.42659 1.81526 2.45772 1.29207 0.00000
-0.94974 -0.65234 0.42659 1.81526 2.45772 1.29207
-0.60841 -0.94974 -0.65234 0.42659 1.81526 2.45772
And if we set the $r$ scalar to $10$, then we get these input values:
U = pinv(GAMMA)*(10-PHI*[0;0])
U =
7.750235
-7.015348
10.210356
-4.402780
8.019733
-2.570849
6.493599
-1.306446
5.454418
-0.462480
4.781299
0.059228
4.395937
0.319370
4.253504
0.348207
4.337430
0.149095
4.595100
So we say that our steady state input signal is $4.6$. If I apply $4.6$ as constant input signal on my state space model above. I get this output:
But if I use this equation instead:
$$U = \Gamma^{\dagger}(R\frac{r}{2}-\Phi x)$$
Then I got these values
U = pinv(GAMMA)*(10/2-PHI*[0;0])
U =
3.875117
-3.507674
5.105178
-2.201390
4.009867
-1.285425
3.246800
-0.653223
2.727209
-0.231240
2.390649
0.029614
2.197969
0.159685
2.126752
0.174103
2.168715
0.074547
2.297550
I use $2.3$ as my steady state input signal and now the output can get to my reference value $r=10$.
Question:
Why does I need to divide the reference scalar value with $2$?