Пример #1
0
def a(N):
    def psi(x, i):
        #return sin((i+1)*x)
        return sin((2 * i + 1) * x)

    #return sin((2*(i+1))*x)

    u, c = least_squares_numerical(
        f,
        psi,
        N,
        x,
        #integration_method='trapezoidal',
        integration_method='scipy',
        orthogonal_basis=True)
    os.system('rm -f *.png')
    u_sum = 0
    print 'XXX c', c
    for i in range(N + 1):
        u_sum = u_sum + c[i] * psi(x, i)
        plt.plot(x,
                 f(x),
                 '-',
                 x,
                 u_sum,
                 '-',
                 legend=['exact', 'approx'],
                 title='Highest frequency component: sin(%d*x)' % (2 * i + 1),
                 axis=[x[0], x[-1], -1.5, 1.5])
        plt.savefig('tmp_frame%04d.png' % i)
        time.sleep(0.3)
    cmd = 'avconv -r 2 -i tmp_frame%04d.png -vcodec libtheora movie.ogg'
Пример #2
0
def a(N):
    def psi(x, i):
        #return sin((i+1)*x)
        return sin((2*i+1)*x)
    #return sin((2*(i+1))*x)

    u, c = least_squares_numerical(f, psi, N, x,
                                   #integration_method='trapezoidal',
                                   integration_method='scipy',
                                   orthogonal_basis=True)
    os.system('rm -f *.png')
    u_sum = 0
    print 'XXX c', c
    for i in range(N+1):
        u_sum = u_sum + c[i]*psi(x, i)
        plt.plot(x, f(x), '-', x, u_sum, '-',
                 legend=['exact', 'approx'],
                 title='Highest frequency component: sin(%d*x)' % (2*i+1),
                 axis=[x[0], x[-1], -1.5, 1.5])
        plt.savefig('tmp_frame%04d.png' % i)
        time.sleep(0.3)
    cmd = 'avconv -r 2 -i tmp_frame%04d.png -vcodec libtheora movie.ogg'