赞
踩
例子:对下面方程进行求解,
1 先标准化
https://blog.csdn.net/qq_40707407/article/details/81709122
- #导入包
- from scipy import optimize
- import numpy as np
-
- #确定c,A,b,Aeq,beq
- c = np.array([2,3,-5])
- A = np.array([[-2,5,-1],[1,3,1]])
- b = np.array([-10,12)]
- Aeq = np.array([[1,1,1]])
- beq = np.array([7])
-
- #求解
- res = optimize.linprog(-c,A,b,Aeq,beq)
- print(res)
- '''
- fun: -14.571428571428571 目标函数最小值
- message: 'Optimization terminated successfully.' 优化是否成功
- nit: 2
- slack: array([3.85714286, 0. ])
- status: 0
- success: True
- x: array([6.42857143, 0.57142857, 0. ]) x的最优解
- '''
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。