I wanted to solve a triplet of simultaneous equations with python. I managed to convert the equations into matrix form below:
For example the first line of the equation would be
v0 = ps0,0 * rs0,0 + ps0,1 * rs0,1 + ps0,2 * rs0,2
+ y(ps0,0 * v0 + ps0,1 * v1 + ps0,2 *v2)
I am solving for v0,v1,v2
. I came across linalg.solve from the numpy
library however I am really lost at rearranging the matrices in the form given in their examples because I have v0,v1,v2
in a [3×1] on the left and a [3×3] on the right.
Best Answer
I'll see if I can't help with the following...
Here's some tips for going between matrices and Python
list
s andnumpy
array
s$$ v = \begin{pmatrix} 9 \\\ 8 \\\ 7 \end{pmatrix} $$
Where I usually see $v_{\left(1\right)} = 9$ and $v_{\left(3\right)} = 7$ is written just a bit like...
... and in most programming languages the index starts at
0
, but it looks like you've got that.Things get interesting with nested lists and multidimensional numpy arrays...
$$ p = \begin{pmatrix} 0.3 & 0.6 & 0.9 \\\ 0.4 & 0.7 & 0.8 \\\ 0.5 & 0.8 & 0.7 \end{pmatrix} $$
Which could be represented as a
numpy.array
as shown...Accessing rows could then look like...
... but accessing cells is likely to frustrate those that want precision at a cellular level...
Even funkier than that...
Hopefully this gave ya some traction on translating your problem into something that a computer will consider, as well as some pointers on how not to use
numpy
. It's fantastic but misusing it can lead to anger, and anger can lead to; well let's not even consider the paths divergent from light ;-)