Exemplo n.º 1
0
from pylab import *

from JSAnimation import IPython_display
import JSAnimation_frametools as J

plotdir = '_plots'  # to store png files for each figure
J.make_plotdir(plotdir, clobber=True)  # ok to clobber if it already exists

x = linspace(0., 10., 1001)
nsteps = 21
dt = 11. / (nsteps + 1)

plotdir = '_plots'

for n in range(nsteps + 1):
    t = n * dt
    x0 = x - 1. - t
    u = sin(20. * x0) * exp(-5. * x0**2)
    clf()
    plot(x, u, 'b')
    ylim(-1.2, 1.2)
    title('Wave packet at t = %8.4f' % t, fontsize=20)

    # Save this frame:
    J.save_frame(n, plotdir, verbose=False)
    #show()

anim = J.make_anim(plotdir)

J.make_html(anim, file_name="Wave.html", title="Advecting wave packet")
Exemplo n.º 2
0
terms = reshape(data[:,0], (n+2, nterms), order='F')
fsums = reshape(data[:,1], (n+2, nterms), order='F')

for k in range(nterms):
    term = terms[:,k]
    fsum = fsums[:,k]

    clf()
    subplot(2,1,1)
    plot(x,fsum,'b-')
    plot(x,f,'r-')
    title('Sum of first %s terms in Fourier series' % (k+1))
    axis([0,pi,-1.0,30.0])

    subplot(2,1,2)
    plot(x,term,'b-')
    title("k = %s term in Fourier series" % (k+1))
    plot(x, 0*x, 'k-')  # plot x-axis
    axis([0,pi,-8,10])


    J.save_frame(k, plotdir, verbose=True)

anim = J.make_anim(plotdir)

description = "Fourier sine series for the function exp(x)"

J.make_html(anim, file_name="FourierSum.html", title=description)
    
Exemplo n.º 3
0
from pylab import *

from JSAnimation import IPython_display
import JSAnimation_frametools as J

plotdir = '_plots'  # to store png files for each figure
J.make_plotdir(plotdir, clobber=True)  # ok to clobber if it already exists

x = linspace(0., 10., 1001)
nsteps = 21
dt = 11. / (nsteps+1)

plotdir = '_plots'

for n in range(nsteps+1):
    t = n*dt
    x0 = x - 1. - t
    u = sin(20.*x0) * exp(-5.*x0**2)
    clf()
    plot(x,u,'b')
    ylim(-1.2, 1.2)
    title('Wave packet at t = %8.4f' % t, fontsize=20)
    
    # Save this frame:
    J.save_frame(n, plotdir,verbose=False)
    #show()

anim = J.make_anim(plotdir)

J.make_html(anim, file_name="Wave.html", title="Advecting wave packet")
Exemplo n.º 4
0
input_data = loadtxt('input_data.txt')
p = float(input_data[2])
seed = int(input_data[4])

n1, n2 = loadtxt('walk.txt', unpack=True)

nsteps = len(n1)
nmax = max(n1.max(), n2.max())  # to set axis limits


for k in range(nsteps):
    steps = range(0,k+1)
    n1steps = n1[0:k+1]
    n2steps = n2[0:k+1]
    clf()
    plot(steps,n1steps,'bo-',label='n1')
    plot(steps,n2steps,'ro-',label='n2')
    axis([0,nsteps,0,nmax])
    legend(loc = 'lower left')
    title('seed = %s' % seed)

    J.save_frame(k, plotdir, verbose=True)

anim = J.make_anim(plotdir)

description = "Gambler's ruin random walk with p = %5.3f" % p

J.make_html(anim, file_name="RandomWalk.html", title=description)
    
Exemplo n.º 5
0
import JSAnimation_frametools as J
from JSAnimation import IPython_display
import numpy as np
import glob

plotdir = '_plots'
J.make_plotdir(plotdir, clobber='true')
fid = open('input_data.txt')
n = int(fid.readline())
tfinal = float(fid.readline())
fid.readline()
nsteps = int(fid.readline())

ax = plt.axes(xlim=(0, np.pi), ylim=(-1, 1))
line, = ax.plot([], [], lw=2)
line.set_data(range(n), range(n))

data = open('solution.txt')
for i in range(nsteps + 1):
    soln = []
    plt.clf()
    for j in range(n + 2):
        soln.append(float(data.readline()))
    plt.axes(xlim=(0, np.pi), ylim=(-1, 1))
    plt.plot(np.arange(0, np.pi, np.pi / (n + 2)), soln)
    plt.plot(np.arange(0, np.pi, np.pi / (n + 2)), soln, 'bo')
    t = "%.3f" % (i * tfinal / nsteps)
    plt.title('time = ' + t)
    J.save_frame(i)
J.make_html(J.make_anim(plotdir))
Exemplo n.º 6
0
data = loadtxt('frames.txt')

terms = reshape(data[:, 0], (n + 2, nterms), order='F')
fsums = reshape(data[:, 1], (n + 2, nterms), order='F')

for k in range(nterms):
    term = terms[:, k]
    fsum = fsums[:, k]

    clf()
    subplot(2, 1, 1)
    plot(x, fsum, 'b-')
    plot(x, f, 'r-')
    title('Sum of first %s terms in Fourier series' % (k + 1))
    axis([0, pi, -1.0, 30.0])

    subplot(2, 1, 2)
    plot(x, term, 'b-')
    title("k = %s term in Fourier series" % (k + 1))
    plot(x, 0 * x, 'k-')  # plot x-axis
    axis([0, pi, -8, 10])

    J.save_frame(k, plotdir, verbose=True)

anim = J.make_anim(plotdir)

description = "Fourier sine series for the function exp(x)"

J.make_html(anim, file_name="FourierSum.html", title=description)