python求曲线交点_在Python中以高精度找到由(x,y)数据给出的两条曲线的交点...

该博客介绍了如何使用Python来精确找到两条曲线的交点。通过定义函数`interpolated_intercepts`,利用插值法计算曲线交点,同时展示了一个示例,将这种方法应用于正弦曲线和线性函数的交点计算,并用matplotlib进行图形化展示。
摘要由CSDN通过智能技术生成

from__future__importdivisionimportnumpyasnpimportmatplotlib.pyplotaspltdefinterpolated_intercepts(x,y1,y2):"""Find the intercepts of two curves, given by the same x data"""defintercept(point1,point2,point3,point4):"""find the intersection between two lines

the first line is defined by the line between point1 and point2

the first line is defined by the line between point3 and point4

each point is an (x,y) tuple.

So, for example, you can find the intersection between

intercept((0,0), (1,1), (0,1), (1,0)) = (0.5, 0.5)

Returns: the intercept, in (x,y) format

"""defline(p1,p2):A=(p1[1]-p2[1])B=(p2[0]-p1[0])C=(p1[0]*p2[1]-p2[0]*p1[1])returnA,B,-Cdefintersection(L1,L2):D=L1[0]*L2[1]-L1[1]*L2[0]Dx=L1[2]*L2[1]-L1[1]*L2[2]Dy=L1[0]*L2[2]-L1[2]*L2[0]x=Dx/D

y=Dy/Dreturnx,y

L1=line([point1[0],point1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值