Python在电路课程中的应用

1 需求

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

2 工具

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

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

3 Sinusoid 章节

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

3.1 复数 1

Code

python 复制代码
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

python 复制代码
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.9 08450732878534 and with angle 12.813149787630694

** Process exited - Return Code: 0 **

Press Enter to exit terminal

相关推荐
Irissgwe41 分钟前
十、LangGraph能力详解:LangGraph 的其他特性
python·ai·langchain·langgraph
吴阿福|一人公司1 小时前
类变量和实例变量的命名规范有哪些避坑点?
开发语言·python
zhoupenghui1681 小时前
AI大模型应用部署之Flask框架使用
运维·python·docker·容器·flask·flask框架
ckjoker1 小时前
手敲三Agent串行流水线,我发现了多Agent协作的隐形杀手
python·agent
稷下元歌1 小时前
七天学会plc加机器视觉之AI 接入 外设模块开发全详细操作文档(全程配套视频按文档实操)
python·sql·qt·贪心算法·r语言·wpf·时序数据库
KaMeidebaby1 小时前
卡梅德生物技术快报|细胞周期检测抗原流式分析:参数调试、软件拟合与问题排查
网络·人工智能·python·网络协议·tcp/ip·算法·机器学习
zmzb01031 小时前
Python课后习题训练记录Day124
开发语言·python
geovindu1 小时前
python: Broadcast Pattern
开发语言·python·设计模式·广播模式
winfredzhang2 小时前
Python 实战:用 wxPython 写一个 MD5 文件查重清理工具
python·sqlite·json·wxpython·md5·预览·查重
装不满的克莱因瓶2 小时前
了解不同机器学习模型的分类
人工智能·python·算法·机器学习·ai·分类·数据挖掘