File:Forward and backward Euler method.png
Forward_and_backward_Euler_method.png (800 × 600 pixels, file size: 36 KB, MIME type: image/png)
Captions
Summary
[edit]DescriptionForward and backward Euler method.png |
English: Comparison of the Forward and Backward Euler methods applied to the differential equation , on the interval . |
Date | |
Source | Own work |
Author | Pred |
Python source code
[edit]import numpy as np
import matplotlib.pyplot as plt
a = float(5) # Maximal value of the domain
n = float(30) # Number of divisions
dt = a/n # Size of each subdivision
t1 = np.arange(0, a, 0.01) # For plotting the analytical solution
t2 = np.arange(0, a, dt) # For plotting the approximations
# The following function solves y'(t) = -y(t)^2 and y(0) = 1
def y(t):
return 1/(1+t)
# Our approximations will simply be given as an array of approximate values
forward_euler = [1] # The initial condition
backward_euler = [1] # is the same for both approximations
for k in range(len(t2)-1):
forward_euler.append(forward_euler[-1] - dt*forward_euler[-1]**2)
backward_euler.append((-1 + np.sqrt(1+4*dt*backward_euler[-1])) / (2*dt))
# Plotting time
plt.plot(t1, y(t1), 'r-', label='Analytical solution')
plt.plot(t2, forward_euler, 'bs', label='Forward Euler method')
plt.plot(t2, backward_euler, 'g^', label='Backward Euler method')
plt.legend()
plt.show()
Licensing
[edit]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.
http://creativecommons.org/publicdomain/zero/1.0/deed.enCC0Creative Commons Zero, Public Domain Dedicationfalsefalse |
File history
Click on a date/time to view the file as it appeared at that time.
Date/Time | Thumbnail | Dimensions | User | Comment | |
---|---|---|---|---|---|
current | 14:53, 8 October 2015 | 800 × 600 (36 KB) | Pred (talk | contribs) | User created page with UploadWizard |
You cannot overwrite this file.
File usage on Commons
There are no pages that use this file.
Metadata
This file contains additional information such as Exif metadata which may have been added by the digital camera, scanner, or software program used to create or digitize it. If the file has been modified from its original state, some details such as the timestamp may not fully reflect those of the original file. The timestamp is only as accurate as the clock in the camera, and it may be completely wrong.
Horizontal resolution | 39.37 dpc |
---|---|
Vertical resolution | 39.37 dpc |