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

相关推荐
kyle~12 小时前
FastAPI --- 将业务能力以 API 的形式提供给外部系统
python·fastapi·前后端
aiotto资源分享13 小时前
Python 写 JSON 文件,程序中途退出会留下什么?
java·python·json·jsondecodeerror
梯度下降者13 小时前
Python信号量,条件变量,事件学习
python·条件变量·事件·信号量·线程通信
MSTcheng.14 小时前
【AI应用实战】用 FastAPI + SSE 做一个自己的 AI 聊天网页:流式输出、多轮对话与完整源码
人工智能·python·大模型·fastapi·sse·ai聊天助手
the局外人15 小时前
Python 实战检索优化:BM25、向量与重排
数据库·后端·python
__underline__15 小时前
冷门Python知识点006篇:Python 类体里的名字,能被"凭空造出来"
后端·python
用户03321266636716 小时前
使用 Python 轻松移除 Excel 文档中的重复行
python·excel
LiaoWL12316 小时前
从零搭一个 RAG 知识库(二):换上语义 Embedding——BGE 实测与阈值重校准
python·大模型·numpy·embedding·向量检索·rag
Dmz丶16 小时前
前端转 AI 100 天 Day 48:向量数据库——100 万向量的毫秒级检索
python
青少儿编程课堂16 小时前
蓝桥杯·全国青少年信息素养大赛·电子学会Python/C++考级:中国剩余定理解析
c++·python·算法·bfs·信息学竞赛