【问题标题】:Convert phase angle equation from Matlab to Python将相位角方程从 Matlab 转换为 Python
【发布时间】:2021-02-10 07:13:55
【问题描述】:

我正在尝试将代码从 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)

最终输出应该是 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 matlab


    【解决方案1】:

    Python 支持开箱即用的Complex 数据类型。 cmath 提供对复数数学函数的访问 (Read More)。请尝试以下操作:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-15
      • 1970-01-01
      相关资源
      最近更新 更多