<file_sep>import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint
import matplotlib.lines as lines
class body:
    def __init__(self, m, V_x, V_y, F, plott, colour):
        self.V_x = V_x
        self.V_y = V_y
        self.mass = m
        self.gravity = F
        self.plott = plott
        self.colour = colour
   
    def position(self):
        t = np.linspace(0, 10, 20)
        x = self.evolveX(t)
        y = self.evolveY(t)
        plott.plot(x,y,'C1')
        
    def evolveX(self, t):
        return self.V_x * t
    
    def evolveY(self, t):
        return self.V_y * t - self.gravity* t**2 /(2.0*self.mass)
    
    
class rotator(body):
    def __init__(self, m, V_x, V_y, F, plott, colour, r, thi, w):
        self.radius = r
        self.angle = thi
        self.freq = w
        body.__init__(self, m, V_x, V_y, F, plott, colour)
        
    def evolve_rot_X(self, t,n):
        return self.V_x * t + ((-1)**n) *self.radius * np.cos(t*self.freq + self.angle)
    
    def evolve_rot_Y(self, t,n):
        return self.V_y * t - self.gravity* t**2 /(2.0*self.mass) + ((-1)**n)*self.radius * np.sin(t*self.freq + self.angle)
    
    def position_rot(self):      
        t = np.linspace(0, 10, 20)
        x1 = self.evolve_rot_X(t,0)
        y1 = self.evolve_rot_Y(t,0)
        l = plott.plot(x1,y1,'ro')
        plt.setp(l, markersize=10)
        plt.setp(l,markerfacecolor='g')
        x2 = self.evolve_rot_X(t,1)
        y2 = self.evolve_rot_Y(t,1)
        l2 = plott.plot(x2,y2,'ro')
        plt.setp(l2, markersize=10)
        plt.setp(l2,markerfacecolor='r')
        for i in range(0,20):
        
            
            l3 = lines.Line2D([x1[i], x2[i]], [y1[i], y2[i]],  lw=2, color='black')
            plott.ax.add_line(l3)
        
    
class pplotter:    
    def __init__(self):
        self.fig = plt.figure()
        self.ax = self.fig.add_subplot(111)
        
    def plot(self, x, y, colour):
        return self.ax.plot(x, y, colour)
    
    def show(self):
        plt.show()
        
plott = pplotter()


object = rotator(1.0, 1.75, 1.0, 0.5, plott, 'g', 1.0, 1.0, 0.5) 
object.position()
object.position_rot()<file_sep>import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint
import matplotlib.lines as lines
class body:
    def __init__(self, m, V_x, V_y, F, plott, colour):
        self.V_x = V_x
        self.V_y = V_y
        self.mass = m
        self.gravity = F
        self.plott = plott
        self.colour = colour
   
    def position(self):
        t = np.linspace(0, 10, 20)
        x = self.evolveX(t)
        y = self.evolveY(t)
        plott.plot(x,y,'C1')
        
    def evolveX(self, t):
        return self.V_x * t
    
    def evolveY(self, t):
        return self.V_y * t - self.gravity* t**2 /(2.0*self.mass)

def system(y,t,coeff,a):
    phi, omega = y
    dy_dt = [omega, coeff*np.sin(phi)]
    return dy_dt
    
class rotator(body):
    def __init__(self, m, V_x, V_y, F, plott, colour, r, thi, omega, E, Q):
        body.__init__(self, m, V_x, V_y, F, plott, colour)
        self.radius = r
        self.angle = thi
        self.freq = omega
        self.field = E 
        self.charge = Q
        
    def ang_on_t(self,t):
        in_cod = [self.angle, self.freq]
        coeff = self.charge * self.field / (self.radius* self.mass)  
        return odeint(system,in_cod,t, args =(coeff,0))[:,0]

        
    def evolve_rot_X(self, t,n):
        return self.V_x * t + ((-1)**n)*self.radius*np.cos( self.angle) + ((-1)**n)*self.radius*np.cos(self.ang_on_t(t))
    
    def evolve_rot_Y(self, t,n):
        return self.V_y * t - self.gravity* t**2 /(2.0*self.mass) + ((-1)**n)*self.radius * np.sin( self.angle) + ((-1)**n)*self.radius*np.sin(self.ang_on_t(t))
    
    def position_rot(self):      
        t = np.linspace(0, 10, 30)
        x1 = self.evolve_rot_X(t,0)
        y1 = self.evolve_rot_Y(t,0)  
        l = plott.plot(x1,y1,'ro')
        plt.setp(l, markersize=10, markerfacecolor='g')
        x2 = self.evolve_rot_X(t,1)
        y2 = self.evolve_rot_Y(t,1)
        l2 = plott.plot(x2,y2,'ro')
        plt.setp(l2, markersize=10, markerfacecolor='r')
        for i in range(0,30):
            l3 = lines.Line2D([x1[i], x2[i]], [y1[i], y2[i]],  lw=2, color='black')
            plott.ax.add_line(l3)
        
    
class pplotter:    
    def __init__(self):
        self.fig = plt.figure()
        self.ax = self.fig.add_subplot(111)
        
    def plot(self, x, y, colour):
        return self.ax.plot(x, y, colour)
    
    def show(self):
        plt.show()
        
plott = pplotter()


object = rotator(1., 2, 1, 0.5, plott, 'g', 1.0, np.pi/2, 0, 1., 0.05) 
object.position()
object.position_rot()
plt.show()
<file_sep>import numpy as np
import matplotlib.pyplot as plt
import math
import imageio
import pylab
from mpl_toolkits.mplot3d import axes3d
import matplotlib
import matplotlib.mlab as mlabD
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter

U0 = 100
class Solving:
    def __init__(self,M,N,eps):
        self.M = M
        self.N = N
        self.eps = eps
        self.Unew = np.zeros((M,N))
        self.Uold = np.ones((M,N))

    def Jacobi(self):  
        i=0
        while i< 1/self.eps:
            self.Uold = self.Unew
            self.Unew[1:self.M-1, 1:self.N-1] = (self.Uold[0:-2, 1:-1]+self.Uold[2:, 1:-1]+self.Uold[1:-1, 2:]+self.Uold[1:-1, 0:-2])/4
            self.Unew[:, 0] = 100
            self.Unew[self.M - 1, :] = 0
            self.Unew[0,:] = 0
            self.Unew[:, self.N - 1] = 0
            i+=1
        return self.Unew


    def plotter(self, U):
        x = np.linspace(0, self.M, self.M)
        y = np.linspace(0, self.N, self.N)
        xgrid, ygrid = np.meshgrid(x, y)
        
        fig = plt.figure()
        ax = fig.gca(projection='3d')
        surf = ax.plot_surface(xgrid, ygrid, U, cmap=cm.coolwarm, linewidth=0, antialiased=False)        
        ax.set_zlim(0, 100)
        ax.zaxis.set_major_locator(LinearLocator(6))
        ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
        fig.colorbar(surf, shrink=0.5, aspect=5)
        plt.show()

    def run(self, method):
        if method == 'Jacobi':            
            self.plotter(self.Jacobi())

test = Solving(100, 100, 0.002)
test.run('Jacobi')  


<file_sep>import numpy as np
import math
from scipy.integrate import odeint
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import matplotlib
import matplotlib.mlab as mlabD
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter


U0=10
a=100
restr = 100
length = a + 1

X = np.linspace(0, a, length)
Y = np.linspace(0, a, length)
Xgrid, Ygrid = np.meshgrid(X, Y)
Uset = np.zeros((length,length))
def U(x,y):
	potential = 0
	k=0
	while k <= restr:
		potential +=  4*U0/(np.pi*(2*k+1)) * ( np.cosh(y*(2*k+1)*np.pi/a) - 1/np.tanh((2*k+1)*np.pi)*np.sinh(y*(2*k+1)*np.pi/a)  )* np.sin(x*(2*k+1)*np.pi/a) 
		k += 1
	return potential

for i in range(length):
		for j in range(length):
			Uset[i][j]  = U(float(i),float(j))



fig = plt.figure()
ax = fig.gca(projection='3d')

# Plot the surface.
surf = ax.plot_surface(Xgrid, Ygrid, Uset, cmap=cm.coolwarm,
                       linewidth=0, antialiased=False)

# Customize the z axis.
ax.set_zlim(0,U0)
ax.zaxis.set_major_locator(LinearLocator(6))
ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
# fig = plt.figure()
# ax = fig.add_subplot(111, projection = '3d')
# CS = plt.contour(Xgrid, Ygrid, Uset,cmap=cm.coolwarm, colors = ('indigo', 'purple' , 'violet', 'aqua' ) , linewidths = 1)
# ax.plot_wireframe(Xgrid, Ygrid, Uset, color = 'black' ,linewidth = 0.3)
fig.colorbar(surf, shrink=0.5, aspect=5)
# plt.clabel(CS, fontsize=9, inline=1)
# plt.title('U(x,y)')
# lab1 = 'potential'
# ax.set_xlabel(r'$Y$')
# ax.set_ylabel(r'$X$')

# ax.legend((lab1), loc='upper left')
# 
# 
plt.show()





