首页 > 其他分享 >习题4.4

习题4.4

时间:2024-10-22 13:01:32浏览次数:6  
标签:4.4 plt rcParams np import 习题 cp

习题4.4代码

import cvxpy as cp
import numpy as np
import pandas as pd
import sympy as sp
sp.init_printing(use_unicode=True)
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif']=['Times New Roman + SimSun + WFM Sans SC']
plt.rcParams['mathtext.fontset']='cm'
plt.rcParams['axes.unicode_minus']=False
plt.rcParams['figure.dpi'] = 200
plt.rcParams['xtick.direction'] = 'in'
plt.rcParams['ytick.direction'] = 'in'
x = cp.Variable(2, integer=True)
c = np.array([[0, 5], [6, 2], [1, 1]])
b = np.array([15, 24, 5]).T
p = np.array([2, 1])

prob = cp.Problem(cp.Maximize(p @ x), [c@x <= b, x >= 0])
prob.solve(solver='GLPK_MI')
print(f'最优解为:{x.value}'), print(f'最优值为:{prob.value}')

标签:4.4,plt,rcParams,np,import,习题,cp
From: https://www.cnblogs.com/DENWOSHUABAZONGSHI/p/18492418

相关文章

  • 习题3.2
    习题3.2代码importnumpyasnpimportpandasaspdimportsympyasspsp.init_printing(use_unicode=True)importmatplotlib.pyplotaspltplt.rcParams['font.sans-serif']=['TimesNewRoman+SimSun+WFMSansSC']plt.rcParams['mathtext......
  • 习题3.3
    习题3.3代码importnumpyasnpimportpandasaspdimportsympyasspsp.init_printing(use_unicode=True)importmatplotlib.pyplotaspltplt.rcParams['font.sans-serif']=['TimesNewRoman+SimSun+WFMSansSC']plt.rcParams['mathtext......
  • 习题2.13
    习题2.13代码importnumpyasnpimportpandasaspdimportsympyasspsp.init_printing(use_unicode=True)importmatplotlib.pyplotaspltplt.rcParams['font.sans-serif']=['TimesNewRoman+SimSun+WFMSansSC']plt.rcParams['mathtex......
  • 习题2.12
    习题2.12代码importnumpyasnpimportpandasaspdimportsympyasspsp.init_printing(use_unicode=True)importmatplotlib.pyplotaspltplt.rcParams['font.sans-serif']=['TimesNewRoman+SimSun+WFMSansSC']plt.rcParams['mathtex......
  • 习题4.3
    习题4.3代码importcvxpyascpimportnumpyasnpimportmatplotlib.pyplotaspltplt.rcParams['font.sans-serif']=['TimesNewRoman+SimSun+WFMSansSC']plt.rcParams['mathtext.fontset']='stix'TimesNewRoman+SimS......
  • 习题5.7
    习题5.7代码importcvxpyimportcvxpyascpimportnumpyasnpimportpandasaspdfromscipy.optimizeimportminimizeimportsympyasspsp.init_printing(use_unicode=True)importmatplotlib.pyplotaspltx=cp.Variable(3,integer=True)cumulative_output=c......
  • 习题6.3
    习题6.3代码importnumpyasnpimportpandasaspdimportcvxpyascpimportnetworkxasnximportmatplotlib.pyplotaspltplt.rcParams['font.sans-serif']=['TimesNewRoman+SimSun+WFMSansSC']plt.rcParams['mathtext.fontset'......
  • 习题6.4
    习题6.4代码importnumpyasnpimportpandasaspdimportcvxpyascpimportnetworkxasnximportmatplotlib.pyplotaspltplt.rcParams['font.sans-serif']=['TimesNewRoman+SimSun+WFMSansSC']plt.rcParams['mathtext.fontset'......
  • 习题6.1
    习题6.1代码importnumpyasnpimportpandasaspdimportcvxpyascpimportnetworkxasnximportmatplotlib.pyplotaspltplt.rcParams['font.sans-serif']=['TimesNewRoman+SimSun+WFMSansSC']plt.rcParams['mathtext.fontset'......
  • python第五章课后习题
    importnumpyasnpimportmathfromscipy.optimizeimportminimize,Boundsdeffunc(x):returnsum(math.sqrt(x[i])foriinrange(100))defcon(x):return1000-np.sum(x[i]*(101-i+1)foriinrange(100))con1={'type':'ineq','fun&#......