国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

二維正交旋轉(zhuǎn)

2023-07-29 11:51 作者:耿大哥講算法  | 我要投稿

# 二維正交旋轉(zhuǎn)

import numpy as np
import matplotlib.pyplot as plt
import matplotlib;matplotlib.rc("font",family='Microsoft YaHei')

#載荷矩陣的初始解
A=np.mat([[0.796,0.424],[0.731,0.610],[0.964,-0.235],[0.953,-0.285],
? ? ? ? ?[0.940,-0.323],[0.919,-0.379],[0.793,0.284],[0.881,0.160]])
#輸出旋轉(zhuǎn)前的載荷矩陣、共同度和Fj的方差貢獻(xiàn)
print('--------旋轉(zhuǎn)前的載荷矩陣--------')
print('分量|組件 ?組件1 ? 組件2 ? 共同度')
for i in range(A.shape[0]):
? ?print('分量'+str(i+1),end='\t')
? ?for j in range(A.shape[1]):print('%.3f'%A[i,j],end='\t')
? ?print('%.3f'%sum(A[i,j]**2 for j in range(A.shape[1])))
print('總貢獻(xiàn)',end='\t')
for j in range(A.shape[1]):print('%.3f'%sum(A[i,j]**2 for i in range(A.shape[0])),end='\t')
print('%.3f'%sum(sum(A[i,j]**2 for i in range(A.shape[0])) for j in range(A.shape[1])),end='\t')
print()
#定義載荷間的總方差函數(shù)
def ff(θ):
? ?Q=np.mat([[np.cos(θ),-np.sin(θ)],
? ? ? ? ? ? ?[np.sin(θ),np.cos(θ)]])
? ?h=[sum(A[i,j]**2 for j in range(A.shape[1])) for i in range(A.shape[0])]
? ?B=A*Q
? ?junzhi=[sum(B[i,j]**2/h[i] for i in range(A.shape[0]))/A.shape[0] for j in range(A.shape[1])]
? ?ff=sum(sum((B[i,j]**2/h[i]-junzhi[j])**2 for i in range(A.shape[0])) for j in range(A.shape[1]))
? ?return ff
#繪制載荷間的總方差函數(shù)隨θ的變化圖像并找到最大值對應(yīng)的θ
x=np.arange(0,np.pi/2,0.01);y=[ff(i) for i in x]
θ=x[y.index(max(y))];plt.plot(x,y,'r-')
plt.plot([θ,θ],[min(y),max(y)],'b*--')
plt.plot([0,θ],[max(y),max(y)],'b*--')
plt.xlabel('旋轉(zhuǎn)角(弧度制)');plt.ylabel('載荷間的總方差')
#計算使載荷間的總方差函數(shù)達(dá)到最大的旋轉(zhuǎn)矩陣Q
Q=np.mat([[np.cos(θ),-np.sin(θ)],[np.sin(θ),np.cos(θ)]])
#計算旋轉(zhuǎn)后的載荷矩陣
B=A*Q
#輸出旋轉(zhuǎn)后的載荷矩陣、共同度和Fj的方差貢獻(xiàn)
print('--------旋轉(zhuǎn)后的載荷矩陣--------')
print('分量|組件 ?組件1 ? 組件2 ? 共同度')
for i in range(B.shape[0]):
? ?print('分量'+str(i+1),end='\t')
? ?for j in range(B.shape[1]):print('%.3f'%B[i,j],end='\t')
? ?print('%.3f'%sum(B[i,j]**2 for j in range(B.shape[1])))
print('總貢獻(xiàn)',end='\t')
for j in range(B.shape[1]):print('%.3f'%sum(B[i,j]**2 for i in range(B.shape[0])),end='\t')
print('%.3f'%sum(sum(B[i,j]**2 for i in range(B.shape[0])) for j in range(B.shape[1])))
print('-'*29)
#輸出旋轉(zhuǎn)角度θ和載荷間的總方差最大值
print('旋轉(zhuǎn)角度θ='+str('%.0f'%(θ*180/np.pi))+'°')
print('載荷間的總方差='+str('%.3f'%ff(θ)))
#輸出使載荷間的總方差函數(shù)達(dá)到最大的旋轉(zhuǎn)矩陣Q
print('-----------變換矩陣-----------')
for i in range(Q.shape[0]):
? ?for j in range(Q.shape[1]):print('%.3f'%Q[i,j],end='\t')
? ?print()
print('-'*29);plt.show()

二維正交旋轉(zhuǎn)的評論 (共 條)

分享到微博請遵守國家法律
应用必备| 郸城县| 图片| 新建县| 桐柏县| 郸城县| 博野县| 固安县| 徐水县| 阿瓦提县| 通道| 开远市| 双峰县| 凤阳县| 内丘县| 天柱县| 铅山县| 新野县| 拜城县| 汉川市| 阿拉善盟| 广南县| 城步| 信阳市| 天津市| 靖宇县| 江口县| 涟水县| 黔西县| 盱眙县| 莲花县| 黄大仙区| 乌拉特后旗| 黄梅县| 德江县| 交城县| 永昌县| 襄樊市| 久治县| 西畴县| 中方县|