点击查看代码
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.optimize import fsolve
def equation_system(vars):
x1, x2, y1, y2 = vars
eq1 = 2*x1 - 3*f(y1) - 4*g(y2) + 1
eq2 = 3*x2 - 2*f(y1) - 6*g(y2) + 2
eq3 = y1 - f(x1) - 3*g(x2) + 3
eq4 = 5*y2 - 4*f(x1) - g(x2) + 1
return [eq1, eq2, eq3, eq4]
# 初始猜测值
initial_guess = [0, 0, 0, 0]
# 解方程组
solution = fsolve(equation_system, initial_guess)
print("解为:", solution)
print("学号:3004")