Created
June 11, 2019 15:44
-
-
Save jdavidrcamacho/e23dcef6f0fdade71188de2faa0d4c46 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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