예제 #1
0
def draw_all(n):
        plt.close()
        x_points = np.linspace(0, 1, n, endpoint=True)
        y_0 = 0.0
        right_boundary = e - 1.0/e + L  # = y'(1)

        for method, color in [
            (explicit_euler, 'r8-'),
            (recount_euler, 'rs-'),
            (runge_kutta, 'yd-'),
        ]:
            last_m = 0
            y_points = method(x_points, 1.0 / n, y_0, last_m, f)
            next_m = get_next_m(x_points, f, method, y_0, right_boundary, last_m, 1.0 / n)

            while abs(next_m - last_m) > 0.01:
                y_points = method(x_points, 1.0 / n, y_0, next_m, f)
                last_m = next_m
                next_m = get_next_m(x_points, f, method, y_0, right_boundary, last_m, 1.0 / n)

            plt.plot(x_points, y_points, color, label=method.__doc__)
        plt.plot(x_points, list(map(real_func, x_points)), 'b*-', label='Original')
        plt.plot(x_points, progon(x_points, right_boundary, 1.0 / n, L), "r*-", label="progon")

        legend = plt.legend(loc='upper left', shadow=True, fontsize='x-large')
        legend.get_frame().set_facecolor('#00FFCC')

        mng = plt.get_current_fig_manager()

        mng.window.state('zoomed')
        # mng.full_screen_toggle()
        plt.show()
예제 #2
0
def main():

    n = 30  # int(sys.argv[1])
    x_points = np.linspace(0, 1, n+1, endpoint=True)
    y_0 = 0
    right_boundary = e - 1.0/e + L
    h = 1.0/n
    colors = ["blue", "purple", "orange", "green"]

    methods = [
        {"f": explicit_euler, "name": "euler"},
        {"f": recount_euler,  "name": "euler with recount"},
        {"f": runge_kutta,    "name": "Runge-Kutta"}
    ]
    p = figure(title="", plot_width=1100, plot_height=600)
    y_points = list(map(real_func, x_points))
    p.line(x=x_points, y=y_points, color="black", legend="real", line_width=2)

    y_points = progon(x_points, right_boundary, h, L)
    p.line(x=x_points, y=y_points, color="red", legend="progon", line_width=2)

    for i in range(len(methods)):
        # y_points = real_func_method(x_points)

        last_m = 0
        y_points = [methods[i]["f"](x_points, h, y_0, last_m, f)]
        next_m = get_next_m(x_points, f, methods[i]["f"], y_0, right_boundary, last_m, h)

        while abs(next_m - last_m) > 0.01:
            y_points.append(methods[i]["f"](x_points, h, y_0, next_m, f))
            last_m = next_m
            next_m = get_next_m(x_points, f, methods[i]["f"], y_0, right_boundary, last_m, h)

        p.line(x=x_points, y=y_points[-1], color=colors[i], legend=methods[i]["name"])

    output_file("{0}_points.html".format(n))
    p.legend.orientation = "top_left"
    show(p)