2.11 已知f(x)=(|x+1|-|x-1|)/2+sinx,g(x)=(|x+3|-|x-3|)/2+cosx,求下列方程组的解 2x1=3f(y1)+4g(y2)-1 3x2=2f(y1)+6g(y2)-2 y1=f(x1)+3g(x2)-3 5y2=4f(x1)+g(x2)-1 python

点击查看代码
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")

posted on 2024-09-12 19:39  黄元元  阅读(16)  评论(0编辑  收藏  举报