Keywords: Instability of Euler's method.svg en This graph shows that the instability of Euler's method when solving the equation <math>y' -2 3y</math> The black curve shows the exact solution the blue squares the numerical approximation with step size <math>h 1</math> and the red circles the numerical solution with <math>h 0 7</math> 2012-03-05 own Jitse Niesen cc-zero Source code <source lang python > 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' </source> Numerical analysis Created with Matplotlib Uploaded with UploadWizard Images with Python source code |