首页 > 其他分享 >习题2.13

习题2.13

时间:2024-10-22 12:58:56浏览次数:5  
标签:plt abs rcParams np import 习题 2.13

习题2.13代码

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'

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'
f = lambda x: (np.abs(x+1) - np.abs(x-1))/2 + np.sin(x)
g = lambda x: (np.abs(x+3) - np.abs(x-3))/2 + np.cos(x)
from scipy.optimize import least_squares
eqs = lambda z: [
3f(z[2])+4g(z[3])-1-2z[0],
2
f(z[2])+6g(z[3])-2-3z[1],
f(z[0])+3g(z[1])-3-z[2],
4
f(z[0])+6g(z[1])-1-5z[3],
f(z[3])+g(z[1])-2-z[0]-z[2],
2f(z[0])-10g(z[2])-5-z[1]-3*z[3]
]
s = least_squares(eqs, np.random.randn(4))
print(s)

标签:plt,abs,rcParams,np,import,习题,2.13
From: https://www.cnblogs.com/DENWOSHUABAZONGSHI/p/18492425

相关文章

  • 习题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&#......
  • 习题6.7代码
    习题6.7代码importnumpyasnpimportpandasaspdimportcvxpyascpimportnetworkxasnximportmatplotlib.pyplotaspltdf=pd.read_excel('F:\python数学建模与算法\源程序\《Python数学建模算法与应用》程序和数据\第6章图论模型\data6.xlsx')D=df.valuesdo......
  • 刷c语言练习题9(牛客网)
    1、12345678char*getmemory(void){    charp[]= "helloworld";    returnp;}voidtest(void){    char*str=NULL;    str=getmemory(); printf(str);}请问运行Test函数会有什么样的结果?A、出错B、输出"helloworld"C、输出空......
  • python第三章课后习题
    efX(n):#差分方程的解return2*(-1)**(n+1)n_values=[0,1,2,3,4,5]forninn_values:print(f"X({n})={X(n)}")print("学号:3028")importnetworkxasnxG=nx.DiGraph()foriinrange(1,7):G.add_node(i)edges=[(1,2),(1,4......