python - Solving overdetermined system in numpy when the value of one variable is already known -


i'm trying solve overdetermined system in python, using numpy.solve function. know value of 1 of variables , know in theory can find unique solution system if can somehow plug in known value.

my system of form axc=b. variables split 2 groups, 1 group of n variables , 1 of t variables (although not matter math). (t*n x t+n) matrix, c variables vector, of length (t+n), , b vector of length (t*n).

how tell numpy.solve (or function in python, please don't recommend least squares, need unique, exact solution, know exists) use known value of 1 of variables?

a simple example of system be:

|1 0 0 1 0|     |n1|     |b1| |1 0 0 0 1|     |n2|     |b2| |0 1 0 1 0|  x  |n3|  =  |b3| |0 1 0 0 1|     |t1|     |b4| |0 0 1 1 0|     |t2|     |b5| |0 0 1 0 1|              |b6|   

the values of elements of b of course known, value of 1 of variables, let's know t1=1. dots don't mean put them there characters wouldn't bunch up.

say need solve

|1 0 0 1 0|     |n1|     |b1| |1 0 0 0 1|     |n2|     |b2| |0 1 0 1 0|  x  |n3|  =  |b3| |0 1 0 0 1|     |t1|     |b4| |0 0 1 1 0|     |t2|     |b5| |0 0 1 0 1|              |b6|   

and know t1. need solve

|1 0 0 0|     |n1|     |b1| - 1 t1 |1 0 0 1|     |n2|     |b2| - 0 t1 |0 1 0 0|  x  |n3|  =  |b3| - 1 t1 |0 1 0 1|     |t2|     |b4| - 0 t1 |0 0 1 0|              |b5| - 1 t1 |0 0 1 1|              |b6| - 0 t1  

so you:

  • remove 4th column matrix

  • subtract right-hand-side 4th column multipled t1

  • remove t1 variable

once have appropriate matrices, call numpy.linalg.solve (or similar). suggest don't concern whether you're "doing least squares", or whether it's unique or not. let linalg.solve find optimal solution (in l2 sense); if solution unique, unique in l2 sense well.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -