예제 #1
0
def test_solve_plane(f, x0, y0):
    """
    Проверяем решение векторных уравнений
    """
    # get iterations
    tol = 1e-9
    xs, ys, zs = solve_plane(f, x0, y0, tol)
    f_eval = f.subs({x: xs[-1], y: ys[-1]})
    assert np.linalg.norm([float(f_eval[0]), float(f_eval[1])]) < tol

    # plot f() lines
    # p = sp.plot(show=False, backend=sp.plotting.plot_backends['matplotlib'])
    p = sp.plot(show=False)
    p.extend(sp.plot_implicit(f[0], depth=1, line_color='k', show=False))
    p.extend(sp.plot_implicit(f[1], depth=1, line_color='k', show=False))

    # plot iterations
    traj = List2DSeries(xs, ys)
    traj.line_color = 'm'
    p.append(traj)
    p.title = f'{f[0]}\n{f[1]}'
    p.xlabel = 'x'
    p.ylabel = 'y'
    p.show()

    # plot accuracy
    plt.figure()
    plt.plot(-np.log10(np.abs(zs)), 'b.:')
    plt.suptitle(p.title)
    plt.xlabel('N step')
    plt.ylabel('Accuracy')
    plt.show()
예제 #2
0
def plot_polytope(poly):
    """Plots the 2D polytope using the functions written in plotting
    module which in turn uses matplotlib backend.
    Parameter
    =========
    poly: Denotes a 2-Polytope
    """
    from sympy.plotting.plot import Plot, List2DSeries

    xl = list(map(lambda vertex: vertex.x, poly.vertices))
    yl = list(map(lambda vertex: vertex.y, poly.vertices))

    xl.append(poly.vertices[0].x)  # Closing the polygon
    yl.append(poly.vertices[0].y)

    l2ds = List2DSeries(xl, yl)
    p = Plot(l2ds, axes='label_axes=True')
    p.show()