簡體   English   中英

將相位角方程從 Matlab 轉換為 Python

[英]Convert phase angle equation from Matlab to Python

我正在嘗試將代碼從 Matlab 調整為 Python。 專門從一組角度測量相位角。 因此,使用下面的 df,我有 5 個帶有相關角度的單獨標簽。 我想測量這些點之間的相位角。 在 Matlab 中,每個Label的角度傳遞給以下內容:

exp(i*ang)

這等於以下內容:

A_ang = 0.9648 + 0.2632i
B_ang = 0.7452 + 0.6668i
C_ang = 0.9923 + 0.1241i
D_ang = 0.8615 + 0.5077i
E_ang = 0.9943 + 0.1066i

然后我除以角度數並通過abs

out = (ac + bc + cc + dc + ec)/5 

total = abs(out)

最終的 output 應該是 0.9708

import pandas as pd
import numpy as np

df = pd.DataFrame({                          
    'Label' : ['A','B','C','D','E'],             
    'Angle' : [0.266252,0.729900,0.124355,0.532504,0.106779],           
    })

Python 支持開箱即用的Complex數據類型。 cmath提供對復數數學函數的訪問(閱讀更多)。 嘗試以下操作:

import cmath 

angs = [0.266252,0.729900,0.124355,0.532504,0.106779]

# Create the complex numbers associated with the angles (with r = 1)
nums = [cmath.cos(ang) + cmath.sin(ang) * 1j for ang in angs]

# Compute the total following what you described. 
total = abs(sum(nums))/len(angs)

print (total) #0.9707616522067346

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM