'How can one swap elements which come from a function?
So I have defined a class called "Particles":
class Particle:
def __init__(self, posInit, momInit, spin):
self.posInit = posInit
self.momInit = momInit
self.spin = spin
def momfT(self, t):
return self.momInit*(math.cos(t))-self.posInit*(math.sin(t))
def posfT(self, t):
return self.posInit*(math.cos(t))+self.momInit*(math.sin(t))
P = [Particle(posInit = i, momInit = j, spin = choice(["up", "down"])) for i,j in zip(Zinitial,Pinitial)]
What I now want to do is switch the positions of the particles if a certain condition is met. So something like the following:
if cond==True:
P[1].posfT[t], P[2].posfT[t1] = P[2].posfT[t1], P[1].posfT[t]
But the above does not work since I am trying to assign to a function a value.
So I am not sure how to do this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
