Skip to content

Instantly share code, notes, and snippets.

@jdavidrcamacho
Created June 11, 2019 15:44
Show Gist options
  • Save jdavidrcamacho/e23dcef6f0fdade71188de2faa0d4c46 to your computer and use it in GitHub Desktop.
Save jdavidrcamacho/e23dcef6f0fdade71188de2faa0d4c46 to your computer and use it in GitHub Desktop.
import numpy as np
import matplotlib.pylab as plt
plt.close('all')
def vanEck(n):
#starts at 0
vanEck = np.array([0])
#first value is 0
i=vanEck[0]
while i < n:
last = vanEck[-1]
pos = np.where(vanEck == last)
# print(i, last, pos[0])
if pos[0].size == 1:
# print('if', 0, last)
vanEck = np.append(vanEck, 0)
else:
# print('else', pos[0][-1], last)
vanEck = np.append(vanEck, pos[0][-1] - pos[0][-2])
i = vanEck[-1]
x = np.linspace(0, n, n+1)
plt.figure
plt.plot(x, 'r--')
plt.plot(vanEck)
return vanEck
def negVanEck(n):
vanEck = np.array([0])
#first value is 0
i=vanEck[0]
while i < n:
last = vanEck[-1]
pos = np.where(vanEck == last)
if pos[0].size == 1:
vanEck1 = np.append(vanEck, -last)
else:
vanEck1 = np.append(vanEck, pos[0][-1] - pos[0][-2])
i = vanEck[-1]
return vanEck
x = np.linspace(0, n, n+1)
plt.figure()
plt.plot(x, 'r--')
plt.plot(vanEck1)
return vanEck
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment