In [1]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from ipywidgets import StaticInteract, RangeWidget, RadioWidget
In [10]:
#Ex = 0
#Ey = 5

m = 1
q = 1

dt = 0.1

def main(Ex,Ey):
    def force():
        return [Ex,Ey]

    def euler_step(x,Vx,y,Vy):
        array = force()
        Fy = Vy
        fy = array[1]
        Fx = Vx
        fx = array[0]
        return [fx*dt, Fx*dt, fy*dt, Fy*dt]

    i = 0
    
    x = 0
    y = 0
    Vx = 1
    Vy = 1

    xposn = []
    yposn = []

    while i<100:
        array = euler_step(x,Vx,y,Vy)
    #        array = rk2_step(k,m,y,dy)
        Vx += array[0]
        x += array[1]
        Vy += array[2]
        y += array[3]
        #print y,dy
        xposn.append(x)
        yposn.append(y)
        i +=1
    return [xposn,yposn]
    
def plot(Ex,Ey):
    fig, ax = plt.subplots(figsize=(4, 3),
                           subplot_kw={'axisbg':'#EEEEEE',
                                       'axisbelow':True})
    ax.grid(color='w', linewidth=2, linestyle='solid')
    alist = main(Ex,Ey)
    xlist = alist[0]
    ylist = alist[1]
    ax.plot(xlist, ylist, lw=5, alpha=0.4)#, label = Ex/Ey)
    ax.legend(loc='upper right')
    #ax.set_xlim(0,2*np.pi)
    #ax.set_ylim(-1, 1)
    return fig
In [15]:
StaticInteract(plot, Ex=RangeWidget(0., 1., 1.), Ey=RangeWidget(0., 1., 1.))
Out[15]:
Ex:
Ey:

testing

In [4]:
Ex = 0
Ey = 5

m = 1
q = 1

x = 0
y = 0
Vx = 1
Vy = 0

dt = 0.1

xposn = []
yposn = []

def force():
    return [Ex,Ey]

def euler_step(x,Vx,y,Vy):
    array = force()
    Fy = Vy
    fy = array[1]
    Fx = Vx
    fx = array[0]
    return [fx*dt, Fx*dt, fy*dt, Fy*dt]

i = 0
while i<100:
    array = euler_step(x,Vx,y,Vy)
#        array = rk2_step(k,m,y,dy)
    Vx += array[0]
    x += array[1]
    Vy += array[2]
    y += array[3]
    #print y,dy
    xposn.append(x)
    yposn.append(y)
    i +=1
In [5]:
plt.plot(xposn,yposn)
Out[5]:
[<matplotlib.lines.Line2D at 0xb1277aac>]
In []: