首页 > 其他分享 >5.7

5.7

时间:2024-10-15 11:36:07浏览次数:8  
标签:0.2 subs 5.7 sp 50 print diff

import cvxpy as cp
import numpy as np
import pandas as pd
from scipy.optimize import minimize
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'

Times New Roman + SimSun + WFM Sans SC

simsum宋体, times new roman -*, simhei黑体, kaiti楷体,

dengxian等线, fangsong仿宋, Microsoft Yahei微软雅黑

plt.rcParams['axes.unicode_minus']=False
plt.rcParams['figure.dpi'] = 200

plt.rcParams['figure.figsize'] = [4, 3]

plt.rcParams['font.size'] = 12

plt.rcParams['xtick.direction'] = 'in'
plt.rcParams['ytick.direction'] = 'in'
x = cp.Variable(3, integer=True)
cumulative_output = cp.cumsum(x)
demand = np.array([40, 60, 80])
cumulative_demand = np.cumsum(demand)
max_output = 100
a, b, c = 50, 0.2, 4
product_fee = cp.sum(ax + bx2)
store_fee = cp.sum(c(cumulative_output - cumulative_demand)) - c(cumulative_output[-1] - cumulative_demand[-1]) # 最后一年的产量必然不大于需求
obj = cp.Minimize(product_fee + store_fee)
cons = [
cumulative_output >= cumulative_demand
]
prob = cp.Problem(obj, cons)
result = prob.solve(solver = cp.GUROBI)
print(f'最优解为:{x.value}'); print(f'最优值为:{prob.value}')
x1, x2, x3 = sp.var('x1 x2 x3')
cumulative_output = [x1, x1+x2, x1+x2+x3]
a, b, c = sp.var('a b c')
p1 = ax1 + bx1
2
p2 = ax2 + bx22
p3 = ax3 + bx3
2
s1 = c(cumulative_output[0] - cumulative_demand[0])
s2 = c
(cumulative_output[1] - cumulative_demand[1])
s3 = 0
p = p1 + p2 + p3
s = s1 + s2 + s3
total_cost = (p + s).simplify()
y = total_cost
dydx1 = sp.diff(y, x1)
dydx2 = sp.diff(y, x2)
dydx3 = sp.diff(y, x3)
x1min, x2min, x3min = sp.solve([dydx1, dydx2, dydx3], [x1, x2, x3]).values()
x1min, x2min, x3min
dx1minda = sp.diff(x1min, a)
dx2minda = sp.diff(x2min, a)
dx3minda = sp.diff(x3min, a)
sx1a = dx1minda * (a/x1min)
sx2a = dx1minda * (a/x2min)
sx3a = dx1minda * (a/x3min)

print('当 a=50, b=0.2, c=4 时')
print('x1对a的灵敏性:', sx1a.subs({a: 50, b: 0.2, c:4}).n(4))
print('x2对a的灵敏性:', sx2a.subs({a: 50, b: 0.2, c:4}).n(4))
print('x3对a的灵敏性:', sx3a.subs({a: 50, b: 0.2, c:4}).n(4))
dx1mindb = sp.diff(x1min, b)
dx2mindb = sp.diff(x2min, b)
dx3mindb = sp.diff(x3min, b)
sx1b = dx1mindb * (b/x1min)
sx2b = dx1mindb * (b/x2min)
sx3b = dx1mindb * (b/x3min)

print('当 a=50, b=0.2, c=4 时')
print('x1对b的灵敏性:', sx1b.subs({a: 50, b: 0.2, c:4}).n(4))
print('x2对b的灵敏性:', sx2b.subs({a: 50, b: 0.2, c:4}).n(4))
print('x3对b的灵敏性:', sx3b.subs({a: 50, b: 0.2, c:4}).n(4))
dx1mindc = sp.diff(x1min, c)
dx2mindc = sp.diff(x2min, c)
dx3mindc = sp.diff(x3min, c)
sx1c = dx1mindc * (c/x1min)
sx2c = dx1mindc * (c/x2min)
sx3c = dx1mindc * (c/x3min)

print('当 a=50, b=0.2, c=4 时')
print('x1对c的灵敏性:', sx1c.subs({a: 50, b: 0.2, c:4}).n(4))
print('x2对c的灵敏性:', sx2c.subs({a: 50, b: 0.2, c:4}).n(4))
print('x3对c的灵敏性:', sx3c.subs({a: 50, b: 0.2, c:4}).n(4))
ymin = y.subs({x1: x1min, x2: x2min, x3: x3min}).simplify()
ymin
dyminda = sp.diff(ymin, a)
dymindb = sp.diff(ymin, b)
dymindc = sp.diff(ymin, c)
sya = dyminda * (a/ymin)
syb = dymindb * (b/ymin)
syc = dymindc * (c/ymin)

print('当 a=50, b=0.2, c=4 时')
print('y对a的灵敏性:', sya.subs({a: 50, b: 0.2, c:4}).n(4))
print('y对b的灵敏性:', syb.subs({a: 50, b: 0.2, c:4}).n(4))
print('y对c的灵敏性:', syc.subs({a: 50, b: 0.2, c:4}).n(4))

标签:0.2,subs,5.7,sp,50,print,diff
From: https://www.cnblogs.com/77i11/p/18467090

相关文章

  • 5.7 生产计划问题
    importnumpyasnpdemands=[40,60,80]max_production=100total_demand=sum(demands)dp=np.full((4,total_demand+1),float('inf'))dp[0][0]=0prev_production=np.full((4,total_demand+1),-1)foriinrang......
  • 数学建模习题5.7
    total_demand=sum(demands)dp=np.full((4,total_demand+1),float('inf'))dp[0][0]=0prev_production=np.full((4,total_demand+1),-1)foriinrange(1,4):prev_demand=sum(demands[:i-1])forjinrange(total_demand+1):ifj<pr......
  • mysql5.7及以后版本设置密码
    开启skip-grant-tables配置由于安装时没有指定密码,需要配置`/etc/my.cnf`(或者`/etc/mysql/my.cnf`等已存在的配置文件),在[mysqld]下一行加上skip-grant-tables,表示无密码登入`vim/etc/my.cnf`输入“:wq”保存退出完成后重启mysqlsystemctlrestartmysqld重启后,重新登录mysq......
  • 【环境配置教程】MYSQL----win系统本地同时安装MySQL5.7.xx、MySQL8.0.xx
    文章目录1.下载mysql8和mysql5.7的压缩包2.解压到本地3.安装MySQL8.xx.xx第一步配置环境变量第二步新建配置文件第三步MySQL数据库初始化第四步临时密码第五步安装并开启mysql8服务第六步登陆mysql8修改密码4.安装MySQL5.7第一步配置环境变量第二步新建......
  • 5.7
    点击查看代码importnumpyasnpdemands=[40,60,80]max_production=100total_demand=sum(demands)dp=np.full((4,total_demand+1),float('inf'))dp[0][0]=0prev_production=np.full((4,total_demand+1),-1)fori......
  • MySQL 5.7增强半同步AFTER SYNC&AFTER COMMIT
    今天主要剖析一下MySQL5.7增强半同步的AFTERSYNC和AFTERCOMMIT的区别。    如果我们生产库对数据的一致性要求比较高,那么我们一般会开启了半同步复制,但在MySQL5.5/5.6里,会存在数据不一致的风险。比如有如下场景,客户端提交了一个事务,master把binlog发送给slave,在发送的期间......
  • linux中mysql5.7安装
    系统要求:CentOS7.664位卸载系统自带mariadb-lib1、rpm-qa|grepmariadb2、rpm-emariadb-libs-5.5.68-1.el7.x86_64 --nodeps 解压tar包:tar-xvfmysql*.tar以下加粗rpm包需要安装:mysql-community-common-5.7.23-1.el7.x86_64.rpmmysql-community-libs-co......
  • 125.785 S1  Binary Model practice
    125.785S12024-- Assignment 2 (Part A and Part B)Duedate:18th October2024Theassignmentis30%tothecourseassessment, including two parts:PartA. Practice binary and paneldata regressions (15%), Part B.Critical Reading (15%).......
  • dedecms5.7后台卡,造成浏览器假死的解决方法
    当你遇到织梦CMS后台菜单点击后卡死的情况时,可以通过屏蔽相关代码来解决这一问题。以下是具体的步骤:1.找到并屏蔽相关代码定位文件:打开织梦CMS安装目录下的 dede/templates/index_body.htm 文件。 直接删除这段代码:<scripttype="text/javascript">function......
  • 虚拟机最后支持 Windows 7的版本是 VMware Workstation 15.5.7
    最新版的VMware已经不再支持Windows7系统了。通过搜寻官网的描述说明,最后的支持版本应该是 VMwareWorkstation15.5.717171714,Win7依然没有放弃使用,于是立即找出了该版本的官方下载地址:VMwareWorkstation15.5.7 | VMwareWorkstationfull15.5.7安装过程中需......