Esempio n. 1
0
def fitLine(points, c='orange', lw=1, alpha=0.6, legend=None):
    '''
    Fits a line through points.

    Extra info is stored in actor.slope, actor.center, actor.variances

    [**Example**](https://github.com/marcomusy/vtkplotter/blob/master/examples/basic/fitline.py)
    '''
    data = np.array(points)
    datamean = data.mean(axis=0)
    uu, dd, vv = np.linalg.svd(data - datamean)
    vv = vv[0]/np.linalg.norm(vv[0])
    # vv contains the first principal component, i.e. the direction
    # vector of the best fit line in the least squares sense.
    xyz_min = points.min(axis=0)
    xyz_max = points.max(axis=0)
    a = np.linalg.norm(xyz_min - datamean)
    b = np.linalg.norm(xyz_max - datamean)
    p1 = datamean - a*vv
    p2 = datamean + b*vv
    l = vs.line(p1, p2, c=c, lw=lw, alpha=alpha)
    l.info['slope'] = vv
    l.info['center'] = datamean
    l.info['variances'] = dd
    return l
def fitLine(points, c='orange', lw=1, alpha=0.6, legend=None):
    '''
    Fits a line through points.

    Extra info is stored in actor.slope, actor.center, actor.variances
    '''
    data = np.array(points)
    datamean = data.mean(axis=0)
    uu, dd, vv = np.linalg.svd(data - datamean)
    vv = vv[0] / np.linalg.norm(vv[0])
    # vv contains the first principal component, i.e. the direction
    # vector of the best fit line in the least squares sense.
    xyz_min = points.min(axis=0)
    xyz_max = points.max(axis=0)
    a = np.linalg.norm(xyz_min - datamean)
    b = np.linalg.norm(xyz_max - datamean)
    p1 = datamean - a * vv
    p2 = datamean + b * vv
    l = vs.line(p1, p2, c=c, lw=lw, alpha=alpha)
    setattr(l, 'slope', vv)
    setattr(l, 'center', datamean)
    setattr(l, 'variances', dd)
    return l
Esempio n. 3
0
    return 1j*(nabla2psi - V*psi) # this is the RH of Schroedinger equation!

def d_dt(psi): # find Psi(t+dt)-Psi(t) /dt with 4th order Runge-Kutta method
    k1 = f(psi)
    k2 = f(psi +dt/2*k1)    
    k3 = f(psi +dt/2*k2)    
    k4 = f(psi +dt  *k3)    
    return (k1 + 2*k2 + 2*k3 + k4)/6

vp = Plotter(interactive=0, axes=2, verbose=0, bg=(0.95,0.95,1))
vp.xtitle = ''
vp.ytitle = 'Psi^2(x,t)'
vp.ztitle = ''

bck = vp.load('data/images/schrod.png', alpha=.3).scale(.0255).pos([0,-5,-.1])
barrier = shapes.line(list(zip(x, V*15,  [0]*len(x))), c='black', lw=2)

lines = []
for i in range(0, Nsteps):	
    for j in range(500): 
        Psi += d_dt(Psi) * dt # integrate for a while before showing things
    A = np.real( Psi*np.conj(Psi) )*1.5 # psi squared, probability(x)
    coords = list(zip(x, A,  [0]*len(x)))
    Aline = shapes.line(coords, c='db', lw=3)
    vp.show([Aline, barrier, bck])
    lines.append([Aline, A]) # store objects

# now show the same lines along z representing time
vp.clear()
vp.camera.Elevation(20)
vp.camera.Azimuth(20)