예제 #1
0
def test_observations():
    global N, T, S, scope, R_0, s_0, Y_0, R_g, s_g, Y_g, M, s_m, u, M_0, s_m_0, M_g, s_m_g

    N = 1

    T = 1

    S = N + 1

    scope = np.zeros((S, 2))
    scope[-1] = [0, T]
    for i in range(N):
        scope[i] = [0, 1]

    R_0 = 100

    s_0 = np.zeros((R_0, S))
    Y_0 = np.zeros(R_0)

    for i in range(R_0):
        s_0[i] = [i / R_0, 0]

    for i in range(R_0):
        Y_0[i] = fn.y(s_0[i])

    R_g = 100

    s_g = np.zeros((R_g, S))
    Y_g = np.zeros(R_g)

    for i in range(R_g):
        s_g[i] = [i % 2, i / 100]

    for i in range(R_g):
        Y_g[i] = fn.y(s_g[i])

    M = 100

    s_m = np.zeros((M, S))

    for i in range(10):
        for j in range(10):
            s_m[i * 10 + j] = [i / 10, j / 10]
    u = np.zeros(M)

    for i in range(M):
        u[i] = fn.U(s_m[i])

    M_0 = 100
    s_m_0 = np.zeros((M_0, S))
    for i in range(10):
        for j in range(10):
            s_m_0[i * 10 + j] = [i / 10 + 1 / 10, -j / 10]

    M_g = 100
    s_m_g = np.zeros((M_g, S))
    for i in range(10):
        for j in range(10):
            s_m_g[i * 10 + j] = [(1.1) * (-1)**(i % 2) + (i) / 10,
                                 j / 10 + 1 / 10]
예제 #2
0
def show_res():
    u_,eps = create_slar()
    fig2 = pylab.figure()
    axes = Axes3D(fig2)

    xx = np.zeros(100)
    tt = np.zeros(100)
    for i in range(100):
        xx[i]= i/100
        

    

    x= np.arange (0, 1.1, 0.1)
    t = np.arange (0, 1.1, 0.1)
    xx, tt = np.meshgrid(x, t)
    yy = np.zeros((xx.shape[0], xx.shape[1]))
    for i in range(xx.shape[0]):
        for j in range(xx.shape[1]):
            yy[i][j] = y_res([xx[i][j],tt[i][j]], u_)
    
            print(yy[i,j], '  ', fn.y([xx[i][j],tt[i][j]]), "ошибка: ", abs(yy[i,j]- fn.y([xx[i,j], tt[i,j]])))

    ## сравнение нулевых наблюдений

    print("сравнение нулевых наблюдений")
    for i in range(cn.R_0):
        print(y_res(cn.s_0[i], u_), '  ', cn.Y_0[i], "ошибка: ", abs(y_res(cn.s_0[i], u_) - fn.y(cn.s_0[i])))

    ## сравнение краевых наблюдений


    print("сравнение краевых наблюдений")
    for i in range(cn.R_g):
        print(y_res(cn.s_g[i], u_), '  ', cn.Y_g[i], "ошибка: ", abs(y_res(cn.s_g[i], u_) - fn.y(cn.s_g[i])))


    ## выводим ошибку

    print('Ошибка: {0:}'.format(eps)) 


    ##
    for i in range(100):
        print('{0:} :: {1:}\n'.format(i/100, abs(fn.y([i/100, 0])-y_res([i/100,0], u_))))
    ##

    axes.scatter(cn.s_0[:,0],cn.s_0[:,1],cn.Y_0, color = 'r', marker= 'x')
    axes.scatter(cn.s_g[:,0],cn.s_g[:,1],cn.Y_g, color = 'g', marker= 'x')
    axes.plot_surface(xx,tt,yy, label = "y(s)")
    axes.set_xlabel("x")                              # подпись у горизонтальной оси х
    axes.set_ylabel("t")
    axes.set_zlabel("y")

    pylab.show()
    fig2.savefig('1_2.png')
    save_result(u_, eps)
예제 #3
0
def save_result(u_, eps):
    result_file = open("Result.txt", "w",encoding='UTF-8')
    result_file.write("Знайдена похибка {0:}\n\n".format(eps))

    result_file.write("Порівняння початкових спостережень:\n")
    for i in range(cn.R_0):
        result_file.write("Знайдене значення: {0:} Реальне значення: {1:}  Похибка {2:}\n".format(y_res(cn.s_0[i], u_), cn.Y_0[i],\
             abs(y_res(cn.s_0[i], u_) - fn.y(cn.s_0[i])) ))

    result_file.write("Порівняння крайових спостережень:\n")
    for i in range(cn.R_0):
        result_file.write("Знайдене значення: {0:} Реальне значення: {1:}  Похибка {2:}\n".format(y_res(cn.s_g[i], u_), cn.Y_g[i],\
             abs(y_res(cn.s_g[i], u_) - fn.y(cn.s_g[i])) ))

    result_file.close()
예제 #4
0
def show_test_y():
    x = np.arange (0, 1, 0.1)
    t = np.arange (0, 1, 0.1)
    xx, tt = np.meshgrid(x, t)
    y = np.zeros((xx.shape[0], xx.shape[1]))
    for i in range(xx.shape[0]):
        for j in range(xx.shape[1]):
            y[i][j] = fn.y([xx[i][j],tt[i][j]])

    fig1 = pylab.figure()
    axes = Axes3D(fig1)

    axes.plot_surface(xx,tt,y)
    axes.set_xlabel("x")                              # подпись у горизонтальной оси х
    axes.set_ylabel("t")
    axes.set_zlabel("y")
    fig1.savefig('1_1.png')
예제 #5
0
def test_observations_new():
    global N, T, S, scope, R_0, s_0, Y_0, R_g, s_g, Y_g, M, s_m, u, M_0, s_m_0, M_g, s_m_g

    N = 1

    T = 1

    S = N + 1

    scope = np.zeros((S, 2))
    scope[-1] = [0, T]
    for i in range(N):
        scope[i] = [0, 1]

    R_0 = 5

    s_0 = np.zeros((R_0, S))
    Y_0 = np.zeros(R_0)

    for i in range(R_0):
        s_0[i] = [i / R_0, 0]

    for i in range(R_0):
        Y_0[i] = fn.y(s_0[i])

    R_g = 6

    s_g = np.zeros((R_g, S))
    Y_g = np.zeros(R_g)

    s_g = np.array([[1., 0.2], [0., .2], [1., .4], [0., .4], [1., .8],
                    [0., .8]])

    # for i in range(R_g):
    #     s_g[i] = [i%2, (i+1)/R_g]

    for i in range(R_g):
        Y_g[i] = fn.y(s_g[i])

    M = 10

    s_m = np.zeros((M, S))

    for i in range(5):
        for j in range(2):
            s_m[i * 2 + j] = [i / 5, j / 4 + 0.1]
    u = np.zeros(M)

    for i in range(M):
        u[i] = fn.U(s_m[i])

    M_0 = 10
    s_m_0 = np.zeros((M_0, S))
    for i in range(5):
        for j in range(2):
            s_m_0[i * 2 + j] = [i / 10 + 1 / 10, -j / 10 - 0.1]

    M_g = 10
    s_m_g = np.zeros((M_g, S))
    for i in range(5):
        for j in range(2):
            s_m_g[i * 2 + j] = [(1.1) * (-1)**(i % 2) + (i) / 10,
                                j / 10 + 1 / 10]