File:Instability of Euler's method.svg

From formulasearchengine
Jump to navigation Jump to search
    Original file (SVG file, nominally 720 × 540 pixels, file size: 23 KB)

    This file is from Wikimedia Commons and may be used by other projects. The description on its file description page there is shown below.

    Summary

    Description
    English: This graph shows that the instability of Euler's method when solving the equation y′=−2.3y. The black curve shows the exact solution, the blue squares the numerical approximation with step size h=1, and the red circles the numerical solution with h=0.7.
    Date
    Source Own work
    Author Jitse Niesen

    Licensing

    I, the copyright holder of this work, hereby publish it under the following license:
    Creative Commons CC-Zero This file is made available under the Creative Commons CC0 1.0 Universal Public Domain Dedication.
    The person who associated a work with this deed has dedicated the work to the public domain by waiving all of their rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.

    Source code

    import matplotlib.pyplot as plt
    from numpy import linspace, exp
    from math import floor
    
    la = -2.3
    end_time = 5
    
    exact_times = linspace(0, end_time, 100)
    exact_solution = exp(la * exact_times)
    
    euler1_h = 1;
    euler1_N = int(floor(end_time / euler1_h))
    euler1_times = [ k * euler1_h for k in range(euler1_N + 1) ]
    euler1_solution = [ (1 + euler1_h * la) ** k for k in range(euler1_N + 1) ]
    
    euler2_h = 0.7;
    euler2_N = int(floor(end_time / euler2_h))
    euler2_times = [ k*euler2_h for k in range(euler2_N + 1) ]
    euler2_solution = [ (1 + euler2_h * la) ** k for k in range(euler2_N + 1) ]
    
    plt.plot(exact_times, exact_solution, '-k',
             euler1_times, euler1_solution, ':sb',
             euler2_times, euler2_solution, ':or', markersize = 10)
    
    plt.gca().tick_params(labelsize = 20)
    plt.savefig('euler-instability.svg')
    

    Captions

    Add a one-line explanation of what this file represents

    Items portrayed in this file

    depicts

    5 March 2012

    File history

    Click on a date/time to view the file as it appeared at that time.

    Date/TimeThumbnailDimensionsUserComment
    current19:02, 10 March 2012Thumbnail for version as of 19:02, 10 March 2012720 × 540 (23 KB)wikimediacommons>Jitse Niesen

    There are no pages that use this file.