Ask Your Question
0

Solver returns empty solution for linear system (but it has a solution)

asked 2020-11-26 18:27:09 +0100

Pro7ech gravatar image

I have three n by n matrices : m_want , m_l andm_r

In the below examples, clearly m_want = m_l * m_r, however if I replace any of the value of either matrix by a variable and try to solve for this variable :

 solution = solve([system[i][j]==want[i][j] for j in range(n) for i in range(n)], variables)

then the solution is empty. Does anyone knows why it behaves like this?

m_l = Matrix([[1, 1, 0, 0, 0, 0, 0, 0],
[0.7071067811865475, -0.7071067811865475, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 1, 0, 0, 0, 0],
[0, 0, 0.4142135623730962, -2.4142135623730976, 0, 0, 0, 0],
[0, 0, 0, 0, 1.0, 1.0, 0, -0.7071067811865483],
[0, 0, 0, 0, 1.414213562373096, -0.7071067811865457, -1, 0],
[0, 0, 0, 0, 0, -0.7071067811865472, 1.0, 1.0],
[0, 0, 0, 0, -1, 0, 1.4142135623730945, -0.7071067811865468]]
)

m_r = matrix([
[1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0],
[0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0],
[0.9238795325112865, 0.0, -0.9238795325112865, 0.0, 0.9238795325112865, 0.0, -0.9238795325112865, 0.0],
[0.0, -0.38268343236509034, 0.0, 0.38268343236509034, 0.0, -0.38268343236509034, 0.0, 0.38268343236509034],
[0.9807852804032295, 0, 0.19509032201612828, 0, -0.9807852804032295, 0, -0.19509032201612828, 0],
[0, -0.27589937928294467, 0, 1.38703984532215, 0, 0.27589937928294467, 0, -1.38703984532215],
[0.8314696123025446, 0, -0.5555702330196017, 0, -0.8314696123025446, 0, 0.5555702330196017, 0],
[0, -1.175875602419359, 0, 0.7856949583871042, 0, 1.175875602419359, 0, -0.7856949583871042]]
)

want =  matrix([
[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
[0.7071067811865475, -0.7071067811865475, 0.7071067811865475, -0.7071067811865475, 0.7071067811865475, -0.7071067811865475, 0.7071067811865475, -0.7071067811865475],
[0.9238795325112865, -0.38268343236509034, -0.9238795325112865, 0.38268343236509034, 0.9238795325112865, -0.38268343236509034, -0.9238795325112865, 0.38268343236509034],
[0.38268343236508906, 0.9238795325112872, -0.38268343236508906, -0.9238795325112872, 0.38268343236508906, 0.9238795325112872, -0.38268343236508906, -0.9238795325112872],
[0.9807852804032303, 0.5555702330196018, 0.1950903220161283, 0.8314696123025453, -0.9807852804032303, -0.5555702330196018, -0.1950903220161283, -0.8314696123025453],
[0.5555702330196017, 0.19509032201612886, 0.8314696123025453, -0.9807852804032305, -0.5555702330196017, -0.19509032201612886, -0.8314696123025453, 0.9807852804032305],
[0.8314696123025446, -0.9807852804032307, -0.5555702330196028, -0.19509032201612753, -0.8314696123025446, 0.9807852804032307, 0.5555702330196028, 0.19509032201612753],
[0.19509032201612703, 0.8314696123025446, -0.9807852804032307, -0.5555702330196031, -0.19509032201612703, -0.8314696123025446, 0.9807852804032307, 0.5555702330196031]])
edit retag flag offensive close merge delete

Comments

Could you please provide an explicit example of system and variables so that we understand what you want to achieve ?

tmonteil gravatar imagetmonteil ( 2020-11-26 18:53:54 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-11-26 19:52:34 +0100

Emmanuel Charpentier gravatar image

updated 2020-11-26 19:58:35 +0100

In the below examples, clearly m_want = m_l * m_r

Nope :

m_l = Matrix([[1, 1, 0, 0, 0, 0, 0, 0],
[0.7071067811865475, -0.7071067811865475, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 1, 0, 0, 0, 0],
[0, 0, 0.4142135623730962, -2.4142135623730976, 0, 0, 0, 0],
[0, 0, 0, 0, 1.0, 1.0, 0, -0.7071067811865483],
[0, 0, 0, 0, 1.414213562373096, -0.7071067811865457, -1, 0],
[0, 0, 0, 0, 0, -0.7071067811865472, 1.0, 1.0],
[0, 0, 0, 0, -1, 0, 1.4142135623730945, -0.7071067811865468]]
)

m_r = matrix([
[1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0],
[0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0],
[0.9238795325112865, 0.0, -0.9238795325112865, 0.0, 0.9238795325112865, 0.0, -0.9238795325112865, 0.0],
[0.0, -0.38268343236509034, 0.0, 0.38268343236509034, 0.0, -0.38268343236509034, 0.0, 0.38268343236509034],
[0.9807852804032295, 0, 0.19509032201612828, 0, -0.9807852804032295, 0, -0.19509032201612828, 0],
[0, -0.27589937928294467, 0, 1.38703984532215, 0, 0.27589937928294467, 0, -1.38703984532215],
[0.8314696123025446, 0, -0.5555702330196017, 0, -0.8314696123025446, 0, 0.5555702330196017, 0],
[0, -1.175875602419359, 0, 0.7856949583871042, 0, 1.175875602419359, 0, -0.7856949583871042]]
)

want =  matrix([
[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
[0.7071067811865475, -0.7071067811865475, 0.7071067811865475, -0.7071067811865475, 0.7071067811865475, -0.7071067811865475, 0.7071067811865475, -0.7071067811865475],
[0.9238795325112865, -0.38268343236509034, -0.9238795325112865, 0.38268343236509034, 0.9238795325112865, -0.38268343236509034, -0.9238795325112865, 0.38268343236509034],
[0.38268343236508906, 0.9238795325112872, -0.38268343236508906, -0.9238795325112872, 0.38268343236508906, 0.9238795325112872, -0.38268343236508906, -0.9238795325112872],
[0.9807852804032303, 0.5555702330196018, 0.1950903220161283, 0.8314696123025453, -0.9807852804032303, -0.5555702330196018, -0.1950903220161283, -0.8314696123025453],
[0.5555702330196017, 0.19509032201612886, 0.8314696123025453, -0.9807852804032305, -0.5555702330196017, -0.19509032201612886, -0.8314696123025453, 0.9807852804032305],
[0.8314696123025446, -0.9807852804032307, -0.5555702330196028, -0.19509032201612753, -0.8314696123025446, 0.9807852804032307, 0.5555702330196028, 0.19509032201612753],
[0.19509032201612703, 0.8314696123025446, -0.9807852804032307, -0.5555702330196031, -0.19509032201612703, -0.8314696123025446, 0.9807852804032307, 0.5555702330196031]])

print(want-(m_l-m_r))

[   1.00000000000000   0.000000000000000    2.00000000000000    1.00000000000000    2.00000000000000    1.00000000000000    2.00000000000000    1.00000000000000]
[  0.000000000000000    1.00000000000000   0.707106781186547   0.292893218813453   0.707106781186547   0.292893218813453   0.707106781186547   0.292893218813453]
[   1.84775906502257  -0.382683432365090   -2.84775906502257  -0.617316567634910    1.84775906502257  -0.382683432365090   -1.84775906502257   0.382683432365090]
[  0.382683432365089   0.541196100146197  -0.796896994738185    1.87301746222690   0.382683432365089   0.541196100146197  -0.382683432365089  -0.541196100146197]
[   1.96157056080646   0.555570233019602   0.390180644032257   0.831469612302545   -2.96157056080646   -1.55557023301960  -0.390180644032257  -0.124362831115997]
[  0.555570233019602 -0.0808090572668158   0.831469612302545   0.406254564918919   -1.96978379539270   0.787915838453362   0.168530387697455  -0.406254564918919]
[   1.66293922460509  -0.980785280403231   -1.11114046603920  -0.195090322016128   -1.66293922460509    1.68789206158978   0.111140466039205  -0.804909677983872]
[  0.195090322016127  -0.344405990116814  -0.980785280403231   0.230124725367501   0.804909677983873   0.344405990116814  -0.433428281969864   0.476982055819046]

Hint : try to use exact values for your equations' coefficients : 0.7071067811865475 reeks $\displaystyle\frac{\sqrt{2}}{2}$, 0.4142135623730962 $\sqrt{2}-1$, etc...

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2020-11-26 18:27:09 +0100

Seen: 249 times

Last updated: Nov 26 '20