问题描述
我正在尝试用 Python 求解一个矩阵方程的二次方程。我正在寻找一个矩阵 Ax
,它是 2x2 以满足
M_1 Ax^2 - M_2 A_x - M_3 = 0
其中 M_1
、M_2
和 M_3
是已知的 2x2 numpy
常量数组,Ax^2
是 Ax
本身的矩阵乘法.
到目前为止我的代码:
import numpy as np
from scipy.optimize import fsolve
# Calibration
gamma = 0.36
beta = 0.98
b_bar = 0.1
psi = 0.001
g = 0.66
rho_x = 0.11
rho_z = 0.95
c_star = 1 + b_bar * np.exp(-g) * (1 - beta * np.exp(-g * (gamma - 1)))
# Matrices
M1 = np.array([[gamma,0],[0,0]])
M2 = np.array([[gamma,psi * b_bar/(beta * np.exp(-gamma * g))],[c_star,b_bar * (beta * np.exp(-gamma * g) - psi * b_bar)]])
M3 = np.array([[0,- b_bar * np.exp(-g)]])
fsolve(lambda Ax: M1 @ Ax @ Ax - M2 @ Ax - M3,np.eye(2))
我收到以下错误:
ValueError: matmul: Input operand 1 has an mismatch in its core dimension 0,with gufunc signature (n?,k),(k,m?)->(n?,m?) (size 4 is different from 2)
从 fsolve
评估函数似乎工作正常。我不知道发生了什么。我错过了什么?在 Python 中解决这个系统的最佳方法是什么?谢谢!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)