Objective - using given max values and coefficients, solve the linear equation within the constraints
Problem - defining the constraint
Code:
import numpy as np
coefficients = np.array([
[0, 9, 6, 9, 4, 0 ],
[0, 9, 7, 7, 3, 2 ],
[0, 9, 5, 9, 3, 2 ],
[0, 11, 2, 6, 4, 5],
[0, 11, 1, 7, 2, 7],
[1, 10, 1, 5, 3, 8]
])
maxPoints = np.array([
[4239100],
[4204767],
[4170434],
[4136101],
[4101768],
[4067435]
])
x = np.linalg.solve(coefficients, maxPoints)
print(x)
Output
[[256694.51339286]
[213778.26339286]
[140820.63839286]
[123654.13839286]
[89321.13839286]
[80737.88839286]]
The issue is that i want to apply a constraint making it so that:
x[0] <= x[1] <= x[2] <= x[3] <= x[4] <= x[5]
Another issue is that this currently only solves this smaller matrix and I need this to work with a much larger matrix were my maxPoints are 1 column by 32 rows and my coefficients are 6 columns by 32 rows. Using the linalg method above it would not solve this.
Heres the error message:
Traceback (most recent call last):
File "Untitled-1.py", line 74, in <module>
X = np.linalg.solve(coefficients, maxPoints)
File "<__array_function__ internals>", line 6, in solve
File "/home/comfortablynumb/.local/lib/python3.7/site-packages/numpy/linalg/linalg.py", line 390, in solve
_assertNdSquareness(a)
File "/home/comfortablynumb/.local/lib/python3.7/site- packages/numpy/linalg/linalg.py", line 213, in _assertNdSquareness
raise LinAlgError('Last 2 dimensions of the array must be square')
numpy.linalg.LinAlgError: Last 2 dimensions of the array must be square
Thanks for the help.
Edit:
Here is the full data set I'm working with
`maxPoints = np.array([
[4239100],
[4204767],
[4170434],
[4136101],
[4101768],
[4067435],
[4033102],
[3998769],
[3964436],
[3930103],
[3895770],
[3861437],
[3827104],
[3792771],
[3758438],
[3724105],
[3689772],
[3655439],
[3621106],
[3586773],
[3552440],
[3518107],
[3483774],
[3449441],
[3415108],
[3380775],
[3346442],
[3312109],
[3277776],
[3243443],
[3209110],
[3174777]])`
`coefficients = np.array([
[0, 9, 6, 9, 4, 0 ],
[0, 9, 7, 7, 3, 2 ],
[0, 9, 5, 9, 3, 2 ],
[0, 11, 2, 6, 4, 5],
[0, 11, 1, 7, 2, 7],
[1, 10, 1, 5, 3, 8],
[2, 9, 1, 5, 2, 9 ],
[2, 8, 2, 4, 3, 9 ],
[2, 8, 2, 3, 4, 9 ],
[2, 8, 1, 4, 1, 12],
[3, 6, 1, 5, 1, 12],
[4, 5, 1, 5, 0, 13],
[5, 4, 1, 5, 0, 13],
[5, 4, 0, 5, 1, 13],
[5, 4, 1, 4, 1, 13],
[5, 4, 2, 3, 1, 13],
[5, 4, 2, 3, 1, 13],
[6, 3, 2, 3, 1, 13],
[6, 3, 2, 2, 1, 14],
[6, 3, 2, 1, 2, 14],
[6, 4, 1, 1, 2, 14],
[6, 4, 1, 1, 0, 16],
[6, 3, 2, 1, 0, 16],
[6, 4, 1, 1, 0, 16],
[6, 4, 1, 1, 0, 16],
[6, 4, 1, 1, 0, 16],
[6, 4, 1, 1, 0, 16],
[7, 3, 1, 1, 0, 16],
[7, 3, 1, 1, 0, 16],
[7, 3, 1, 1, 0, 16],
[7, 3, 1, 1, 0, 16],
[7, 3, 1, 1, 0, 16]
])`

