2.11(学号:3025)

tjs200461 / 2025-01-25 / 原文

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 = 3
x2 - 2f(y1) - 6g(y2) + 2
eq3 = y1 - f(x1) - 3g(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("学号:3025")