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 = 2x1 - 3f(y1) - 4g(y2) + 1
eq2 = 3x2 - 2f(y1) - 6g(y2) + 2
eq3 = y1 - f(x1) - 3g(x2) + 3
eq4 = 5y2 - 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("学号:3025")
标签:return,3025,np,abs,y1,y2,2.11 From: https://www.cnblogs.com/tjs200461/p/18508984