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

相关推荐
花酒锄作田18 分钟前
[python]基于动态实例的命令处理设计
python
计算机毕设定制辅导-无忧学长41 分钟前
InfluxDB 与 Python 框架结合:Django 应用案例(三)
开发语言·python·django
惜.己44 分钟前
python中appium
开发语言·python·appium
小沈熬夜秃头中୧⍤⃝1 小时前
Python 入门指南:从零基础到环境搭建
开发语言·python
睿思达DBA_WGX1 小时前
Python 程序设计讲义(54):Python 的函数——函数概述
开发语言·python
真智AI1 小时前
打破数据质量瓶颈:用n8n实现30秒专业数据质量报告自动化
大数据·运维·人工智能·python·自动化
蛋仔聊测试1 小时前
基于 Playwright(python) 的前端性能测试脚本实现
前端·python
鹿邑网爬1 小时前
Python抖音关键词视频爬取实战:批量下载与分析热门视频数据
爬虫·python
砌玉成璧2 小时前
Flask一个用户同时只能在一处登录实现
后端·python·flask
2202_756749692 小时前
02 基于sklearn的机械学习-KNN算法、模型选择与调优(交叉验证、朴素贝叶斯算法、拉普拉斯平滑)、决策树(信息增益、基尼指数)、随机森林
python·算法·决策树·随机森林·机器学习·sklearn