习题2.9代码
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'
x, y = sp.var('x y')
f = [x2 - y - x - 3, x + 3*y - 2]
s = sp.solve(f, [x, y])
print(s)
from scipy.optimize import fsolve
f = lambda x: [x[0]2 - x[1] - x[0] - 3, x[0] + 3*x[1] - 2]
print(fsolve(f, [0, 0]), fsolve(f, [2, 0]), sep='\n')