2.11
import numpy as np
from scipy.optimize import fsolve
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)
def equations(variables):
x1, x2, y1, y2 = variables[:4]
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) + 6 * g(x2) - 1)
return [eq1, eq2, eq3, eq4]
initial_guess = [0, 0, 0, 0]
numeric_solution = fsolve(equations, initial_guess)
print("数值解:", numeric_solution)

3022
浙公网安备 33010602011771号