摘要:
import numpy as np matches = np.array([ [0, 1, 0, 1, 1, 1], # 1队 [0, 0, 0, 1, 1, 1], # 2队 [1, 1, 0, 1, 0, 0], # 3队 [0, 0, 0, 0, 1, 1], # 4队 [0, 0, 1, 阅读全文
摘要:
import numpy as np distances = np.array([ [0, 2, 7, np.inf, np.inf, np.inf], [2, 0, 4, 6, 8, np.inf], [7, 4, 0, 1, 3, np.inf], [np.inf, 6, 1, 0, 1, 6] 阅读全文
摘要:
initial_costs = [2.5, 2.6, 2.8, 3.1] salvage_values = [2.0, 1.6, 1.3, 1.1] maintenance_costs = [0.3, 0.8, 1.5, 2.0] dp = [[float('inf')] * 2 for _ in 阅读全文
摘要:
import heapq def prim(graph, start): num_nodes = len(graph) visited = [False] * num_nodes min_heap = [(0, start, -1)] mst_cost = 0 mst_edges = [] whil 阅读全文
摘要:
edges = [ ("Pe", "T", 13), ("Pe", "N", 68), ("Pe", "M", 78), ("Pe", "L", 51), ("Pe", "Pa", 51), ("T", "N", 68), ("T", "M", 70), ("T", "L", 6 阅读全文
摘要:
import networkx as nx import matplotlib.pyplot as plt G = nx.Graph() nodes = ['v1', 'v2', 'v3', 'v4', 'v5', 'v6'] G.add_nodes_from(nodes) edges = [ (' 阅读全文
摘要:
MAX_A = 15 MAX_B = 24 MAX_DEBUG = 5 products = [ {"name": "Ⅰ", "A_hours": 1, "B_hours": 6, "debug_hours": 1, "profit": 2}, # 假设产品Ⅰ至少使用1小时设备A {"name": 阅读全文
摘要:
import matplotlib.pyplot as plt import numpy as np import cvxpy as cp x=cp.Variable(6,pos=True) obj=cp.Minimize(x[5]) a1=np.array([0.025, 0.015, 0.055 阅读全文
摘要:
import numpy as np def f(x): return (abs(x + 1) - abs(x - 1)) / 2 + np.sin(x) def g(x): return (abs(x + 3) - abs(x - 3)) / 2 + np.cos(x) 假设我们有一些初始猜测值( 阅读全文
摘要:
import numpy as np from scipy.linalg import eig 定义矩阵 A = np.array([[-1, 1, 0], [-4, 3, 0], [1, 0, 2]]) 计算特征值和特征向量 eigenvalues, eigenvectors = eig(A) 打 阅读全文
摘要:
import numpy as np def f(x): return (abs(x + 1) - abs(x - 1)) / 2 + np.sin(x) def g(x): return (abs(x + 3) - abs(x - 3)) / 2 + np.cos(x) from scipy.op 阅读全文
摘要:
from scipy.integrate import quad import numpy as np 第一部分:抛物线旋转体(修正后) def V1_quad(y): return np.pi * (4*y - y**2) V1_corrected, _ = quad(V1_quad, 1, 3) 阅读全文
摘要:
import sympy as sp 定义变量 x, y = sp.symbols('x y') 定义方程组 equation1 = sp.Eq(x**2 - y - x, 3) equation2 = sp.Eq(x + 3*y, 2) 解方程组 solutions = sp.solve((equ 阅读全文
摘要:
import numpy as np 初始化系数矩阵A和常数项向量b n = 1000 A = np.zeros((n, n)) b = np.arange(1, n+1) 填充系数矩阵A for i in range(n): A[i, i] = 4 # 对角线元素为4 if i < n-1: A[ 阅读全文
摘要:
import numpy as np 定义系数矩阵A和常数项向量b A = np.array([[4, 2, -1], [3, -1, 2], [11, 3, 0]]) b = np.array([2, 10, 8]) 使用numpy的lstsq求解最小二乘解 x, residuals, rank, 阅读全文
摘要:
import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D 模拟高程数据(假设数据已经过某种方式插值或生成) 这里我们创建一个简单的40x50网格,并填充随机高程值 x = np 阅读全文
摘要:
import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D 定义参数u和v u = np.linspace(-2, 2, 400) v = np.linspace(0, 2 * 阅读全文
摘要:
import numpy as np import matplotlib.pyplot as plt 定义x的范围 x = np.linspace(-10, 10, 400) 创建一个2行3列的子图布局 fig, axs = plt.subplots(2, 3, figsize=(12, 8)) 遍 阅读全文
摘要:
import numpy as np import matplotlib.pyplot as plt 定义x的范围 x = np.linspace(-10, 10, 400) 创建一个图形和坐标轴 plt.figure(figsize=(10, 6)) ax = plt.gca() 循环绘制每条曲线 阅读全文
摘要:
import numpy as np import matplotlib.pyplot as plt from scipy.integrate import quad def fun(t, x): return np.exp(-t) * (t ** (x - 1)) x = np.linspace( 阅读全文