File:Instability of Euler's method.svg

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

Original file (SVG file, nominally 720 × 540 pixels, file size: 23 KB)

Captions

Captions

Add a one-line explanation of what this file represents

Summary

[edit]
Description
English: This graph shows that the instability of Euler's method when solving the equation . The black curve shows the exact solution, the blue squares the numerical approximation with step size , and the red circles the numerical solution with .
Date
Source Own work
Author Jitse Niesen

Licensing

[edit]
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

[edit]
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')

File history

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

Date/TimeThumbnailDimensionsUserComment
current17:02, 10 March 2012Thumbnail for version as of 17:02, 10 March 2012720 × 540 (23 KB)Jitse Niesen (talk | contribs)

There are no pages that use this file.

File usage on other wikis

The following other wikis use this file: