Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import numpy as np
def d1(c, x):
return sum(abs(x-c))
#Data points: x1,x2,x3,…,xNx1,x2,x3,…,xN
def generate_nods(N):
x = np.linspace(-1.0, 1.0, num=N)
e = np.random.uniform(-0.1, 0.1, size=N)
#x.sort()
return x+e
def generate_points(x, z, f):
”’ ordinates for z ”’
d = np.zeros_like(z)
for i in range(size(z)):
d[i] = f(z[i], x)
return d
N = 5
x = generate_nods(N)
print(x)
d = generate_points(x, x, d1)
print(d)
#Points for plotting
n = 481
z = np.linspace(-1.2, 1.2, num=n)
y = generate_points(x, z, d1)
plot(z, y)
plot(x, d, ‘bo’)
title(‘$d_{1}(x)$’)
xlabel(‘$x$’)
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.