Trying to plot a function with three variables
I'm trying to plot a function with three variables, attraction
, repulsion
, and epsilon
, but the plot
function doesn't seem to be doing what I want it to.
class Vertex:
def __init__(self):
self.acceleration = vector((0, 0, 0))
self.velocity = vector((0, 0, 0))
self.position = self._random_vector()
def _rand(self):
return RR.random_element(-1, 1)
def _random_vector(self):
return vector((self._rand(), self._rand(), self._rand()))
def _repulsion(self, x1, x2, c_repulsion=0, c_epsilon=0.1):
return (c_repulsion / c_epsilon + abs(x1-x2)^2)*((x1-x2)/abs(x1-x2))
def _attraction(self, x1, x2, c_attraction):
return (x1-x2)*-1*c_attraction
def iterate(self, vertices, c_repulsion=0, c_attraction=0, c_epsilon=0, c_friction=0.60):
for v in vertices:
if v is not self:
self.acceleration += self._attraction(self.position, v.position, c_attraction)
self.acceleration -= self._repulsion(self.position, v.position, c_repulsion, c_epsilon)
self.acceleration -= (self.acceleration * c_friction)
self.velocity += self.acceleration
self.position += self.velocity
return self.position
def _distance(self, p1, p2):
return sqrt((p1[0] + p2[0])^2 + (p1[0] + p2[0])^2 + (p1[0] + p2[0])^2)
def distance(self, v):
return self.distance(self.position, v.position)
def reset(self):
self.acceleration = vector((0, 0, 0))
self.velocity = vector((0, 0, 0))
self.position = random_vector()
v1 = Vertex()
v2 = Vertex()
repulsion, attraction, epsilon = var('repulsion, attraction, epsilon')
def distance(repulsion, attraction, epsilon):
for i in range(100):
v1.iterate(
[v1, v2],
c_repulsion=repulsion,
c_attraction=attraction,
c_epsilon=epsilon
)
return v1.distance(v2)
plot(distance(repulsion, attraction, epsilon),
(repulsion, -1, 1),
(attraction, -1, 1),
(epsilon, -1, 1)
)
I'll post the code below, could someone share with me what I'm doing wrong, please? To be specific, my code doesn't produce any output whatsoever.