Python 如何通过Pytork有效地求解四元方程组?
我需要解一个非线性方程组,如下所示:Python 如何通过Pytork有效地求解四元方程组?,python,matrix,optimization,pytorch,solver,Python,Matrix,Optimization,Pytorch,Solver,我需要解一个非线性方程组,如下所示: def trySolveEquation(V, L): #The equation to solve is: #{ (V . Ct) ^ 2 = 1 #{ (L + u) . Ct = 0 #C and u are the unknowns, C is a vector and u is a scalar, Ct is a vector transposed from C. #V is a vector
def trySolveEquation(V, L):
#The equation to solve is:
#{ (V . Ct) ^ 2 = 1
#{ (L + u) . Ct = 0
#C and u are the unknowns, C is a vector and u is a scalar, Ct is a vector transposed from C.
#V is a vector with dimension equal to Ct, L is a square matrix, they are known.
#u is Lagrange multiplier, and it's unknown.
#'.' means matrix multiply.
dim = V.shape[0]
assert L.shape[0] == dim and L.shape[1] == dim
C = torch.zeros((dim))
Ct = C.view((dim, 1))
u = 0
'*Solve the equation here.*'
print('C=', C)
print('u=', u)
return C, u
C的尺寸大约是10,这个方程组将被求解多达10亿次,所以通过torch实现它很好,这样GPU就可以被利用。有什么方法比梯度下降法更好吗?PyTorch只在本机上支持求解线性方程组(例如
torch.solve
,torch.linalg.solve
)。但是你可以试试,例如:
房间板/qpth
Pytork的快速可微QP求解器