Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
模拟这个题目的过程
# 模拟这个题目的过程
# https://mp.weixin.qq.com/s?__biz=MzIzMTc0NzAwMA==&mid=2247483759&idx=1&sn=933d3522dcc197b547696ad522652b8b&key=281224a0b07438ec8edb2e3a289a23f072754ac6a4b26d9e3ce3e38cca13ec9be38b36c21c8340b80c94deb264a2ff916029a398d55725d4128d04bbbef6653083d77490729372eca7851e6b4673eac2&ascene=0&uin=MTQ0OTk4MDMwMA%3D%3D&devicetype=iMac+MacBookPro11%2C1+OSX+OSX+10.12.4+build(16E195)&version=12020510&nettype=WIFI&fontScale=100&pass_ticket=1TrgoYI6A%2Fe9EM1BEXmWAwjoNDPwfCcCsU5W1LgXMf%2BV1wgkhzYikLhX8b3Ru9op
import numpy as np
import matplotlib.pyplot as plt
def f0(xarr, a, c, d):
l = []
cyclelen = d + 1.0 * c / a
for x in xarr:
cycle = np.floor(x / cyclelen);
basey1 = c * cycle;
basey2 = c * cycle + c;
y = basey1 + (x % cyclelen) * a;
if y > basey2 : y = basey2;
l.append(y)
return l
def f1(xarr) : return f0(xarr, 120, 200, 1)
def f2(xarr) : return f0(xarr, 100, 200, 1)
x = np.arange(0, 50, 0.1);
plt.plot(x, f1(x), label='P1')
plt.plot(x, f2(x), label='P2')
plt.plot(x, np.subtract(f1(x), f2(x)), label='distance')
plt.grid(b=True, which='both', color='0.65',linestyle='-')
plt.legend(loc='best')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.