0

I'm not very experienced with using python and I am trying to solve a system of equations. Here's an example of how it would look:

x1 + 2x2 + 3x3 + ... + x52 = some number A

7x1 + 8x2 + x3 + ... + 4x52 = some number B

9x1 + 3x2 + x3 + ... + x52 = some number C

So it would only have a few rows with a lot of columns.

I know there are many solutions but not all will work.

Alex A.
  • 5,466
  • 4
  • 26
  • 56
  • 1
    Use Numpy matrices with [`numpy.linalg.solve`](http://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.solve.html). – Alex A. Jun 17 '15 at 17:21
  • @AlexA.:- Thanks for pointing that. Closing it as duplicate! – Rahul Tripathi Jun 17 '15 at 17:27
  • "So it would have a few rows with a lot of columns.". I don't get it. Shouldn't you have as many equations as variables? –  Jun 17 '15 at 17:58

1 Answers1

0

From your description, it sounds as though your problem is under-determined, so you can't hope to solve the set of equations uniquely but seek a "best" solution in some sense. The usual first approach to this kind of problem is the linear least-squares solution, which NumPy provides a function for: numpy.linalg.lstsq.

xnx
  • 24,509
  • 11
  • 70
  • 109
  • So I forgot to mention that each variable has an upper and lower limit. So for example the only solutions acceptable for x1 would be from 100 to 1000. Each variable would work like this. Would I still use numpy? – apezdedookie Jun 19 '15 at 23:16