Python在电路课程中的应用

1 需求

   课程中有大量的计算,电路方程、复数计算,之前都是用的MATLAB online,可现在要过期了,只能更换平台。

2 工具

https://www.online-python.com/

Python3 在线工具 | 菜鸟工具 (runoob.com)

3 Sinusoid 章节

涉及到复数计算,相关函数见 cmath --- 关于复数的数学函数 — Python 3.11.5 文档

3.1 复数 1

Code

import cmath,math
a=complex(6*math.cos(30/180*math.pi),6*math.sin(30/180*math.pi)) # transfer to randian
a=cmath.rect(6,30/180*math.pi)
b=complex(5,-3)
c=complex(2,4)
d=(a+b)/c
print(f' the result is {d} ')
print(f' real  {d.real}, img  {d.imag}')
 
print(f'in polar {abs(d)}   {cmath.phase(d)/math.pi*180} ')

 Result:

 the result is (1.0196152422706632  -2.0392304845413265j) 
 real  1.0196152422706632, img  -2.0392304845413265
in polar 2.27992899261212   -63.43494882292201 

3.2 复数2 

Code

import cmath,math

a=cmath.rect(40,50/180*math.pi)
b=cmath.rect(20,-30/180*math.pi)

c=cmath.sqrt(a+b)
print(f' a is {a} , b is {b}, sqrt (a+b) is {c} or  amplitude is {abs(c)} and with angle {cmath.phase(c)/math.pi*180}')

Result
 

 a is (25.711504387461574+30.64177772475912j) , b is (17.320508075688775-9.999999999999998j), sqrt (a+b) is (6.7364198203407835+1.5321029771950059j) or  amplitude is 6.908450732878534 and with angle 12.813149787630694


** Process exited - Return Code: 0 **
Press Enter to exit terminal

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

做一个码农都是奢望

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值