-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
babcc1c
commit 346fc5f
Showing
37 changed files
with
2,685 additions
and
1,588 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# ETD4RK Thresholds | ||
|
||
ETD4RK is a solver based on _Exponential time differencing for stiff systems_ (Cox & Matthews 2002), equations (26)-(29). | ||
|
||
In its equations intervene differences of functions and their truncated Taylor series, such as $e^x-1-x$. | ||
|
||
Due to the floating point precision of python, for small enough $x$, this difference becomes numerically unstable, and should be replaced by the higher order term of the Taylor series. | ||
|
||
This folder contains the `thresholds.py` script which showcases both the exact numerical function and the higher-order taylor term, as a means to determine at which threshold we should switch from one to the other. Those thresholds are the ones used in `Framework.ETD4RK`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
"""see README.md: empirical determination of thresholds between numerical differences and higher-order Taylor terms in ETD4RK""" | ||
|
||
import numpy as np | ||
from matplotlib import pyplot as plt | ||
|
||
# res = (e - 1) / (hc/h) | ||
f = lambda x: (np.exp(x / 2) - 1) / x | ||
g = lambda x: np.ones_like(x) * 1 / 2 | ||
|
||
x = np.logspace(-10, 0, int(1e4)) | ||
plt.loglog(x, f(x), label="numerical difference") | ||
plt.loglog(x, g(x), "--", label="higher-order taylor") | ||
plt.loglog(x, f(x) - g(x), ":", label="diff") | ||
plt.axvline(x=1e-6, linestyle="--", label="threshold", color="black") | ||
plt.xlabel("$x$") | ||
plt.title("$(e^{x/2}-1)/x$") | ||
plt.legend() | ||
plt.show() | ||
|
||
# res = (-4 - hc + e * (4 - 3 * hc + hc ** 2)) / ((hc)**3/h) | ||
f = lambda x: (-4 - x + np.exp(x) * (4 - 3 * x + x**2)) / x**3 | ||
g = lambda x: np.ones_like(x) * 1 / 6 | ||
|
||
plt.loglog(x, f(x), label="numerical difference") | ||
plt.loglog(x, g(x), "--", label="higher-order taylor") | ||
plt.loglog(x, np.abs(f(x) - g(x)), ":", label="diff") | ||
plt.axvline(x=1e-3, linestyle="--", label="threshold", color="black") | ||
plt.xlabel("$x$") | ||
plt.title("$(-4 - x + e^x (4 - 3x + x^2)) / x^3$") | ||
plt.legend() | ||
plt.show() | ||
|
||
# res = (2 + hc + e * (-2 + hc)) / ((hc)**3/h) | ||
f = lambda x: (2 + x + np.exp(x) * (-2 + x)) / x**3 | ||
g = lambda x: np.ones_like(x) * 1 / 6 | ||
|
||
plt.loglog(x, f(x), label="numerical difference") | ||
plt.loglog(x, g(x), "--", label="higher-order taylor") | ||
plt.loglog(x, np.abs(f(x) - g(x)), ":", label="diff") | ||
plt.axvline(x=1e-3, linestyle="--", label="threshold", color="black") | ||
plt.xlabel("$x$") | ||
plt.title("$(2 + x + e^x (-2+x)) / x^3$") | ||
plt.legend() | ||
plt.show() | ||
|
||
# res = (-4 - 3 * hc - hc ** 2 + e * (4 - hc)) / ((hc)**3/h) | ||
f = lambda x: (-4 - 3 * x - x**2 + np.exp(x) * (4 - x)) / x**3 | ||
g = lambda x: np.ones_like(x) * 1 / 6 | ||
|
||
plt.loglog(x, f(x), label="numerical difference") | ||
plt.loglog(x, g(x), "--", label="higher-order taylor") | ||
plt.loglog(x, np.abs(f(x) - g(x)), ":", label="diff") | ||
plt.axvline(x=6e-3, linestyle="--", label="threshold", color="black") | ||
plt.xlabel("$x$") | ||
plt.title("$(-4-3 x - x^2 + e^x (4 - x)) / x^3$") | ||
plt.legend() | ||
plt.show() |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.