Exemple #1
0
def test_simpson_integeration2D(x, y, test_f) :
    i = 2
    xx = []
    yy = []
    err = []
    I1 = []
    I2 = []
    I = []
    II = (der_f4_1(np.max(x))-der_f4_1(np.min(x)))*der_f4_2(y)
    while i< 52:
        xx.append(np.linspace(np.min(x),np.max(x), i))
        yy.append(np.linspace(np.min(y),np.max(y), i))
        I1.append(simpson_integration(xx[i-2], test_f4_1))
        I2.append(simpson_integration(xx[i-2], test_f4_2)) 
        I.append(I1[i-2]*I2[i-2])
        err.append(LA.norm(np.array(I[0:i])-II, 2))
        i += 1        
    fig4 = plt.figure
    fig4.Figure()
    ax41 = plt.pyplot.subplot(121)
    ax42 = plt.pyplot.subplot(122)
    ax41.plot(np.array(xx[-2]), I, 'r', np.array(xx[-2]), II*np.ones((i-2,)) , 'g')
    ax41.legend(['num_integral','ana_integral'])
    ax41.set_title('num and ana integeral of x*exp(-(x**2+y**2))')
    plt.pyplot.savefig('num_and_ana_int_fun4.pdf',dpi=200)    
    ax42.plot(np.array(xx[-2]), err)
    ax42.legend(['norm2'])
    ax42.set_title('norm2 of integeral of x*exp(-(x**2+y**2))')
    plt.pyplot.savefig('num_and_ana_int_fun4_error .pdf',dpi=200)
    return err, I
Exemple #2
0
def test_simpson_integeration2(x, test_f):
    i = 2
    xx = []
    err = []
    I = []
    II = der_f2(np.max(x)) - der_f2(np.min(x))
    while i < 52:
        xx.append(np.linspace(np.min(x), np.max(x), i))
        I.append(simpson_integration(xx[i - 2], test_f))
        err.append(LA.norm(np.array(I[0:i]) - II, 2))
        i += 1
    fig2 = plt.figure
    fig2.Figure()
    ax21 = plt.pyplot.subplot(121)
    ax22 = plt.pyplot.subplot(122)
    ax21.plot(np.array(xx[-2]), I, 'r', np.array(xx[-2]),
              II * np.ones((i - 2, )), 'g')
    ax21.legend(['num_integral', 'ana_integral'])
    ax21.set_title('num and ana integeral of sin(x)/x')
    plt.pyplot.savefig('num_and_ana_int_fun2.pdf', dpi=200)
    ax22.plot(np.array(xx[-2]), err)
    ax22.legend(['norm2'])
    ax22.set_title('norm2 of integeral of sin(x)/x')
    plt.pyplot.savefig('num_and_ana_int_fun2_error.pdf', dpi=200)
    return err, I
Exemple #3
0
def test_simpson_integeration3(x, test_f) :
    i = 2
    xx = []
    err = []
    I = []
  
    while i< 52:
        xx.append(np.linspace(np.min(x),np.max(x), i))
        I.append(simpson_integration(xx[i-2], test_f))
        err.append(LA.norm(np.array(I[0:i])-der_f3(0), 2))
        i += 1        
    fig3 = plt.figure
    fig3.Figure()
    ax31 = plt.pyplot.subplot(311)
    ax32 = plt.pyplot.subplot(312)
    ax33 = plt.pyplot.subplot(313)
    cx1 =[x1.real for x1 in I]
    cy1 =[y1.real for y1 in I]    
    ax31.plot(cx1, cy1)
    ax31.legend(['num_integral'])
    ax31.set_title('num integeral of exp(sin(x**3))')
    plt.pyplot.savefig('num_int_fun3.pdf',dpi=200)
    cnums = der_f3(0)*np.ones((i-2,))
    cx =[x.real for x in cnums]
    cy =[y.real for y in cnums]
    ax32.plot(cx, cy, 'o')
    ax32.legend(['ana_integral'])
    ax32.set_title('ana integeral of exp(sin(x**3))')
    plt.pyplot.savefig('ana_int_fun3.pdf',dpi=200)
    cx2 =[x2.real for x2 in err]
    cy2 =[y2.real for y2 in err]
    ax33.plot(cx2, cy2)
    ax33.legend(['norm2'])
    ax33.set_title('norm2 of integeral of exp(sin(x**3))')
    plt.pyplot.savefig('ana_num_int_fun3_error.pdf',dpi=200)
    return err, I
def integrate_a3():
    x = np.linspace(0, 5, 10000)
    eval_integral = simpson_integration(x, f_a3)
    print('Integral a3 =', eval_integral)
def integrate_a2():
    x = np.linspace(0.001, 1,
                    10000)  #Not from 0 to 1, because we divide through x
    eval_integral = simpson_integration(x, f_a2)
    print('Integral a2 =', eval_integral)
def integrate_a1():
    x = np.linspace(0, 5 * 10**4,
                    100000)  #Linspace defines the integration limits
    eval_integral = simpson_integration(x, f_a1)
    print('Integral a1 =', eval_integral)