gpt4 book ai didi

python - 2 个地 block 的交集(鼠尾草)

转载 作者:太空宇宙 更新时间:2023-11-04 06:03:01 25 4
gpt4 key购买 nike

你能帮我找到图形中的交点吗

import numpy as np
import matplotlib.pyplot as plt

@interact
def foo(count=(1,10,1), t=slider(100,1000,100,default=100)):

plt.cla()

dt = 1/t

x = np.arange(1, step=dt)
xl = np.arange(1, step=.000001)

W = np.zeros(t, np.dtype(float))

#Iteration Logarithm
l = np.sqrt(2*xl*ln(ln(1/xl)))
plt.plot(xl, l,'r--')
plt.plot(xl, -l,'r--')

mu, sig = 0, 1

for ITER in range(1, count+1): #count of W[i] in plot
for i in range(1, len(W)):
W[i] = W[i-1] + np.random.normal(mu, sig) * np.sqrt(dt) #Wiener process
plt.plot(x,W)

plt.xlabel('t',fontsize=26)
plt.ylabel('W(t)',fontsize=26)
plt.grid(True)
@interact
def _dee(deep=slider(0.0001, .4, 0.001, default=.2)): #scale
plt.xlim(0, deep)
plt.ylim(-.5, .5)
plt.show()

我使用 https://cloud.sagemath.com无法实现,如何找到图形相互交叉的点。谢谢。

最佳答案

虽然我不熟悉 sage,但给定两个采样函数得到交点应该很容易 - 只需计算它们之间的差异每次符号都会有一个交点变化

step=0.1
x= np.arange(-5,5, step=step)

f1 = x**2 - 4
f2 = -x**2 + 4

dif= f2-f1
dif_sign= dif/np.abs(dif) #just the sign of the function
dif_sign_dif= np.diff(dif_sign) #places where the sign changes
change_idxs= np.where(dif_sign_dif!=0)[0] #indexes where the sign changes
print -5+change_idxs*step

输出:

[-2.  2.]

不过,由于您要添加布朗运动,因此偶尔会出现“误报”。

关于python - 2 个地 block 的交集(鼠尾草),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23742909/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com