我一辈子都搞不懂为什么和努比的争吵会导致错误的答案。正确答案在SymPy矩阵中。有人能告诉我为什么努比不能进行正确的计算吗?我快疯了。谢谢您!
# simplex tableau
import numpy as np
import sympy as sp
#NumPy
simplex = np.array([[2,4,3,1,0,0,0, 400],
[4,1,1,0,1,0,0, 200],
[7,4,4,0,0,1,0, 800],
[-3,-4,-2,0,0,0,1, 0]])
simplex[1,:] = simplex[1,:] - (1/4)*simplex[0,:]
print(simplex)
#SymPy
simplex = sp.Matrix([[2,4,3,1,0,0,0, 400],
[4,1,1,0,1,0,0, 200],
[7,4,4,0,0,1,0, 800],
[-3,-4,-2,0,0,0,1, 0]])
simplex[1,:] = simplex[1,:] - (1/4)*simplex[0,:]
simplex
纽比:
[[ 2 4 3 1 0 0 0 400]
[ 3 0 0 0 1 0 0 100]
[ 7 4 4 0 0 1 0 800]
[ -3 -4 -2 0 0 0 1 0]]
同情:
Matrix([
[ 2, 4, 3, 1, 0, 0, 0, 400],
[3.5, 0, 0.25, -0.25, 1, 0, 0, 100.0],
[ 7, 4, 4, 0, 0, 1, 0, 800],
[ -3, -4, -2, 0, 0, 0, 1, 0]])
最佳答案
NumPy数组有一个整数类型。它实际上不能容纳浮点数字。给它一个浮点数据类型:
simplex = np.array(..., dtype=float)