提问人:Luna Lovegood 提问时间:4/24/2023 最后编辑:Luna Lovegood 更新时间:4/26/2023 访问量:27
使用逆矩阵进行plot_surface
plot_surface with inverse matrix
问:
我正在尝试使用 matplotlib 的 plot_surface 函数绘制 3D 表面。我的 f(x, y) 函数很复杂。我正在使用逆矩阵,这会导致错误“数组的最后 2 维必须是正方形”。
但是当我尝试使用 matplotlib 的绘图绘制曲面时,一切都很好,没有发生错误,我得到了一个线框曲面。 如何解决逆矩阵和绘图曲面的这个问题?
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
from sympy import *
fig = plt.figure()
ax = Axes3D(fig)
x = np.arange(52, 100, 4)
y = np.arange(1.5, 2, 0.05)
X,Y = np.meshgrid(x,y)
def f(x,y):
L = 0.53*y
l_2 = 0.2*y
x_s = 0.004
m_1 = 0.19*x
m_2 = 0.62*x
l_1 = 0.3167*y
R = 0.45
r = 0.41
h = 0.38
b = 0.2
d = 0.12
M_0 = 2.2
k = 5
g = 9.8
Q = x*g*x_s
I_1 = M_0*d**2
I_2 = m_1*L**2/3
I_3 = m_2*(b**2+l_2**2)/3
A_0 = M_0*(R-r)**2+2*m_1*((R-h)**2+b**2)+m_2*(R-h+l_2)**2+I_1+I_3
B_0 = 2*m_1*l_1*(R-h)+m_2*L*(R-h+l_2)
C_0 = 2*m_1*l_1**2+m_2*L**2+2*I_2
w = g*(M_0*r+2*m_1*h-m_2*(l_2-h))
v = -g*(2*m_1*l_1+m_2*L)
M = np.array([[A_0, B_0], [B_0, C_0]])
N = np.array([[k, -k], [-k, k]])
K = np.array([[w, 0], [0,v]])
D = np.array([-1,1])
M_1 = np.linalg.inv(M) #error
N_0 = np.dot(M_1, N)
K_0 = np.dot(M_1, K)
D_0 = np.dot(M_1, D)
D_0 = D_0.reshape(-1,1)
F_0 = np.concatenate ([eye(2), zeros(2)], axis = 1)
F = np.concatenate([-N_0, -K_0], axis = 1)
F = np.concatenate([F, F_0])
F = np.array(F, dtype = float)
zer = np.array([[0],[0]])
H = np.concatenate([D_0, zer])
t,T = np.linalg.eig(F)
for i in range(4):
if re(t[i]) > 0:
j = i
T_0 = np.linalg.inv(T)
P = np.dot(T_0,H)
p = P[j,0]
s = t[j]
s = float(s)
return Q*abs(p)*180/(pi*s*abs(T_0[j,2]))
ax.plot_surface(X,Y,f(X,Y))
plt.show()
答: 暂无答案
评论
M
(2, 2, 10, 12)
10
12
M
M
concatenate
stack
vstack
dstack
block
hstack
column_stack
np.linalg.inv(M.transpose((2,3,0,1))
M_1