小编Ele*_*l95的帖子

Python 中涉及分数和浮点数的计算精度损失

import sympy as sp
from fractions import Fraction

new_matrix_aux = [['X',   'B', 'X1', 'X2', 'X3', 'X4', 'X5', 'U1', 'U2'], 
                  ['X2', 10/3,    0,    1,  2/3,  1/3, -2/3, -1/3,  2/3],  
                  ['X1',  4/3,    1,    0,  2/3, -2/3,  1/3,  2/3, -1/3]]

z_function = "Z = 1 * X1 + 2 * X2 + 3 * X3 + 0 * X4 + 0 * X5 + M * U1 + M * U2"


lista_de_operaciones_zj = []

for j in range(1, len(new_matrix_aux[0])):
    z = z_function
    for …
Run Code Online (Sandbox Code Playgroud)

python math sympy fractions python-3.x

0
推荐指数
1
解决办法
62
查看次数

标签 统计

fractions ×1

math ×1

python ×1

python-3.x ×1

sympy ×1