def graph(f, n, xmin, xmax, axis, resolution = 1001):
    """
    Plots p_L based on points taken from f(x)
    """
    x = []
    y = []
    y_p = []
    x_f = []
    y_f = []
    step = (xmax - xmin) / float(n)
    step_res = (xmax - xmin) / float(resolution)
    for i in xrange(n):
        x.append(xmin + i * step)
    for elem_x in x:
        y.append(f(elem_x))

    for i in xrange(resolution):
        x_f.append(xmin + i * step_res)
    for elem in x_f:
        y_f.append(f(elem))

    for elem_x in x:
        y_p.append(L1.p_L(elem_x, x, y))

    plt.plot(x, y_p, 'ro')
    plt.plot(x_f, y_f, '.')
    plt.axis(axis)
    plt.show()
def graph(f, n, xmin, xmax, axis, resolution=1001):
    """
    Plots p_L based on points taken from f(x)
    """
    x = []
    y = []
    y_p = []
    x_f = []
    y_f = []
    step = (xmax - xmin) / float(n)
    step_res = (xmax - xmin) / float(resolution)
    for i in xrange(n):
        x.append(xmin + i * step)
    for elem_x in x:
        y.append(f(elem_x))

    for i in xrange(resolution):
        x_f.append(xmin + i * step_res)
    for elem in x_f:
        y_f.append(f(elem))

    for elem_x in x:
        y_p.append(L1.p_L(elem_x, x, y))

    plt.plot(x, y_p, 'ro')
    plt.plot(x_f, y_f, '.')
    plt.axis(axis)
    plt.show()
def graph2(f, n, xmin, xmax, legend_list, resolution=1001):
    for element in n:
        x_actual = np.linspace(xmin, xmax, element)
        y_actual = f(x_actual)
        x_array = np.linspace(xmin, xmax, resolution)
        y_array = np.array([p1.p_L(x, x_actual, y_actual) for x in x_array])
        plot(x_actual, y_actual, 'o')
        plot(x_array, y_array, '-')
    legend(legend_list, loc=9)
    title('Sin and Interpolating Functions from 0 to Pi')
    xlabel('x')
    ylabel('y')
def graph2(f, n, xmin, xmax, legend_list, resolution=1001):
    for element in n:
        x_actual = np.linspace(xmin, xmax, element)
        y_actual = f(x_actual)
        x_array = np.linspace(xmin, xmax, resolution)
        y_array = np.array([p1.p_L(x, x_actual, y_actual) for x in x_array])
        plot(x_actual, y_actual, 'o')
        plot(x_array, y_array, '-')
    legend(legend_list, loc=9)
    title('Sin and Interpolating Functions from 0 to Pi')
    xlabel('x')
    ylabel('y')
def graph(f, n, xmin, xmax, resolution=1001):
    x_values = np.linspace(xmin, xmax, n)
    y_values = f(x_values)
    x_arr = np.linspace(xmin, xmax, resolution)
    y_arr = []
    for x in x_arr:
        y_arr.append(p1.p_L(x, x_values, y_values))
    plt.plot(x_values, y_values, 'ko')
    plt.plot(x_arr, y_arr)
    plt.title('Interpolation Polynomial and sin(x) from 0 to pi')
    plt.xlabel('x')
    plt.ylabel('y')
    plt.xlim(-0.1, 3.2)
    plt.ylim(-0.1, 1.1)
def graph(f, n, xmin, xmax, resolution=1001):
    """Creates a graph of a given function f by both plotting n evenly spaced
    points of the function on the given interval as black circles, and by plotting
    a blue line of the given resolution by the interpolating function p_L and its
    property L_k of the module Lagrange_poly1"""
    x_actual = np.linspace(xmin, xmax, n)
    y_actual = f(x_actual)
    x_array = np.linspace(xmin, xmax, resolution)
    y_array = np.array([p1.p_L(x, x_actual, y_actual) for x in x_array])
    plot(x_actual, y_actual, 'ko')
    plot(x_array, y_array, 'b-')
    xlim([-0.01, math.pi + 0.01])
    ylim([0, 1.1])
    title('Sin and Interpolating Function from 0 to Pi')
    xlabel('x')
    ylabel('y')
def graph(f, n, xmin, xmax, resolution=1001):
    """Creates a graph of a given function f by both plotting n evenly spaced
    points of the function on the given interval as black circles, and by plotting
    a blue line of the given resolution by the interpolating function p_L and its
    property L_k of the module Lagrange_poly1"""
    x_actual = np.linspace(xmin, xmax, n)
    y_actual = f(x_actual)
    x_array = np.linspace(xmin, xmax, resolution)
    y_array = np.array([p1.p_L(x, x_actual, y_actual) for x in x_array])
    plot(x_actual, y_actual, 'ko')
    plot(x_array, y_array, 'b-')
    xlim([-0.01, math.pi + 0.01])
    ylim([0, 1.1])
    title('Sin and Interpolating Function from 0 to Pi')
    xlabel('x')
    ylabel('y')
def test_p_l(xp = np.linspace(0,math.pi, 5), yp = np.array([math.sin(y) for y in np.linspace(0,math.pi, 5)]) ):
    plt.plot(xp, yp)
    Lagrange_poly1.test_p_l(xp, yp)
def p_L(x, xp, yp):
    return Lagrange_poly1.p_L(x, xp, yp)
def test_p_l(xp=np.linspace(0, math.pi, 5),
             yp=np.array([math.sin(y) for y in np.linspace(0, math.pi, 5)])):
    Lagrange_poly1.test_p_l(xp, yp)
def L_k(x, k, xp):
    return Lagrange_poly1.L_k(x, k, xp)
def p_L(x, xp, yp):
    return Lagrange_poly1.p_L(x, xp, yp)