Defining a constraints matrix

116 Views Asked by At

I have a short question,

Would it be correct to define the following constraints: $$ \begin{align*} - L_0 - A_0 + L_1 &= 0, \\ - L_1 - A_1 + L_2 &= 0, \\ - L_2 - A_2 + L_3 &= 0, \\ &\vdots \\ - L_{119} - A_{119} + L_{120} &= 0 \end{align*} $$

Into a constraints matrix that looks like this:

import numpy as np
H = np.zeros((120, 240))
for i, p in zip(range(120), range(120)):
    for j in range(i, i+3):
        if j - i < 2:
            H[p][j] = -1
        else:
            H[p][j] = 1  
1

There are 1 best solutions below

5
On

If the $A_{i}$ are unknown, I think the constraint system should be

\begin{equation*} \underbrace{\left(\begin{array}{cccccccccccccc} -1 & 1 & 0 & 0 & 0 & 0 & \cdots & 0 & 0 & -1 & 0 & 0 & \cdots & 0\\ 0 & -1 & 1 & 0 & 0 & 0 & \cdots & 0 & 0 & 0 &-1 & 0 & \cdots & 0\\ 0 & 0 & -1 & 1 & 0 & 0 & \cdots & 0 & 0 & 0 & 0 & -1 & \cdots & 0\\ \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots\\ 0 & 0 & 0 & 0 & 0 & 0 & \cdots & -1 & 1 & 0 & 0 & 0 & \cdots & -1 \end{array}\right)}_{120\times 241}\underbrace{\left(\begin{array}{c} L_{0}\\ L_{1}\\ L_{2}\\ \vdots \\ L_{120}\\ A_{0}\\ A_{1}\\ A_{2}\\ \vdots\\ A_{119} \end{array}\right)}_{241\times 1} = \underbrace{\left(\begin{array}{c} 0\\ 0\\ \vdots\\ 0 \end{array}\right)}_{120\times 1} \end{equation*}

Otherwise, I think it should be

\begin{equation*} \underbrace{\left(\begin{array}{cccccc} -1 & 1 & 0 & \cdots & 0 & 0\\ 0 & -1 & 1 & \cdots & 0 & 0\\ \vdots & \vdots & \vdots & \vdots & \vdots & \vdots\\ 0 & 0 & 0 & \cdots & -1 & 1\\ \end{array}\right)}_{120 \times 121}\underbrace{\left(\begin{array}{c} L_{0}\\ L_{1}\\ \vdots\\ L_{119}\\ L_{120} \end{array}\right)}_{121\times 1} = \underbrace{\left(\begin{array}{c} A_{0}\\ A_{1}\\ \vdots\\ A_{119} \end{array}\right)}_{120\times 1} \end{equation*}

The way you're constructing your matrix, it seems like you're sort of mixing up the positions of the $A_{i}$ and the $L_{i}$.