ZeroDivisionError: matrix is numerically singular
ZeroDivisionError: matrix is numerically singular
我正在尝试用 5 个未知数求解 5 个方程。
from sympy import *
w1, w2, w3, h2, h3 = symbols('w1 w2 w3 h2 h3')
tan = 8.89/19
h1 = 17.73
wt = 19
a1 = h1*w1+(w1*w1*tan)/2
a2 = h2*w2+(w2*w2*tan)/2
a3 = h3*w3+(w3*w3*tan)/2
a4 = w2*(h1+w1*tan-h2)+w3*(h1+(w1+w2)*tan-h3)
at = (h1*wt)+(wt*wt*tan)/2
eq1 = a1 - a2
eq2 = a1 - a3
eq3 = a1 - a4
eq4 = a1+a2+a3+a4-at
eq5 = w1+w2+w3-wt
answer = nsolve((eq1, eq2, eq3, eq4, eq5), (w1, w2, w3, h2, h3), (1, 1, 1, 1, 1))
print(answer)
但是我收到一个错误:
ZeroDivisionError: matrix is numerically singular
更多调用堆栈:
File "/home/m3/Downloads/map/v-env/lib64/python3.6/site-packages/mpmath/calculus/optimization.py", line 660, in __iter__
s = self.ctx.lu_solve(Jx, fxn)
File "/home/m3/Downloads/map/v-env/lib64/python3.6/site-packages/mpmath/matrices/linalg.py", line 226, in lu_solve
A, p = ctx.LU_decomp(A)
File "/home/m3/Downloads/map/v-env/lib64/python3.6/site-packages/mpmath/matrices/linalg.py", line 136, in LU_decomp
raise ZeroDivisionError('matrix is numerically singular')
我无法弄清楚我的方程式有什么问题。这些方程式适用于几何。这些方程试图将一个几何区域分成 4 个相等的区域。任何人都可以提供一些提示。谢谢
按照建议 ,通过添加解决了错误:
eq1 = nsimplify(eq1, rational=1)
eq2 = nsimplify(eq2, rational=1)
eq3 = nsimplify(eq3, rational=1)
eq4 = nsimplify(eq4, rational=1)
eq5 = nsimplify(eq5, rational=1)
然后,用不同的起始值调用nsolve
:
answer = nsolve((eq1, eq2, eq3, eq4, eq5), (w1, w2, w3, h2, h3), (6, 7, 8, 9, 10))
但是收到了另一条消息:
ValueError: Could not find root within given tolerance.
(5846.21208448752672242 > 2.16840434497100886801e-19)
Try another starting point or tweak arguments.
我正在尝试用 5 个未知数求解 5 个方程。
from sympy import *
w1, w2, w3, h2, h3 = symbols('w1 w2 w3 h2 h3')
tan = 8.89/19
h1 = 17.73
wt = 19
a1 = h1*w1+(w1*w1*tan)/2
a2 = h2*w2+(w2*w2*tan)/2
a3 = h3*w3+(w3*w3*tan)/2
a4 = w2*(h1+w1*tan-h2)+w3*(h1+(w1+w2)*tan-h3)
at = (h1*wt)+(wt*wt*tan)/2
eq1 = a1 - a2
eq2 = a1 - a3
eq3 = a1 - a4
eq4 = a1+a2+a3+a4-at
eq5 = w1+w2+w3-wt
answer = nsolve((eq1, eq2, eq3, eq4, eq5), (w1, w2, w3, h2, h3), (1, 1, 1, 1, 1))
print(answer)
但是我收到一个错误:
ZeroDivisionError: matrix is numerically singular
更多调用堆栈:
File "/home/m3/Downloads/map/v-env/lib64/python3.6/site-packages/mpmath/calculus/optimization.py", line 660, in __iter__
s = self.ctx.lu_solve(Jx, fxn)
File "/home/m3/Downloads/map/v-env/lib64/python3.6/site-packages/mpmath/matrices/linalg.py", line 226, in lu_solve
A, p = ctx.LU_decomp(A)
File "/home/m3/Downloads/map/v-env/lib64/python3.6/site-packages/mpmath/matrices/linalg.py", line 136, in LU_decomp
raise ZeroDivisionError('matrix is numerically singular')
我无法弄清楚我的方程式有什么问题。这些方程式适用于几何。这些方程试图将一个几何区域分成 4 个相等的区域。任何人都可以提供一些提示。谢谢
按照建议
eq1 = nsimplify(eq1, rational=1)
eq2 = nsimplify(eq2, rational=1)
eq3 = nsimplify(eq3, rational=1)
eq4 = nsimplify(eq4, rational=1)
eq5 = nsimplify(eq5, rational=1)
然后,用不同的起始值调用nsolve
:
answer = nsolve((eq1, eq2, eq3, eq4, eq5), (w1, w2, w3, h2, h3), (6, 7, 8, 9, 10))
但是收到了另一条消息:
ValueError: Could not find root within given tolerance. (5846.21208448752672242 > 2.16840434497100886801e-19)
Try another starting point or tweak arguments.