43
votes
Accepted
Which Runge-Kutta method is more accurate: Dormand-Prince or Cash-Karp?
Since I just finished optimizing a lot of them in software, DifferentialEquations.jl, I decided to just lay out a comparison of the main Order 4/5 methods. The Fehlberg method was left out because it'...
26
votes
Accepted
How can I avoid catastrophic cancellation?
Take
\begin{align}
1-\sqrt{ 1-x^2} &= (1-\sqrt{ 1-x^2})\frac{1+\sqrt{ 1-x^2}}{1+\sqrt{ 1-x^2}}\\
&= \frac{x^2}{1+\sqrt{ 1-x^2}}
\end{align}
So
\begin{align}
y = x\sqrt{\frac{1}{2+2\sqrt{1-x^2}}...
15
votes
Matrix multiplication accuracy Matlab vs Python
First, see Mark L. Stone's answers, which is completely correct. Second, realize that this is the reason why people told you to use relative errors in your numerical analysis class. :)
Third, the ...
14
votes
Practical example of why it is not good to invert a matrix
Here is a quick example which is very practical related to memory usage in PDEs. When one discretizes the Laplace operator, $\Delta u$, for example, in the Heat Equation
$$ u_t = \Delta u + f(t,u) .$$...
14
votes
Accepted
Whittaker-Shannon interpolation: Accuracy dies with speedup; can it be fixed?
I was able to reproduce the behavior reported in the question, and traced the observed inaccuracies to the following line:
...
14
votes
12
votes
Accepted
Accurate and efficient computation of the inverse Langevin function
The inverse Langevin function $\mathcal{L}^{-1}(x)$ is an odd function. Therefore one needs to consider only approximation on the interval $[0, 1]$; the negative half-plane is treated via symmetry ...
12
votes
Accepted
Practical example of why it is not good to invert a matrix
Normally there are some principal reasons to prefer solve a linear system respect to use the inverse. Briefly:
problem with the conditional number (@GoHokies comment)
problem in the sparse case (@...
12
votes
Accepted
What is the best method of computing $a^{(k)}/k!$?
If the programming environment provides an implementation of the beta function $\mathrm{B}(x,y)$ this computation is straightforward and usually accurate. We have
$$x^{(k)} = \frac{\Gamma(x+k)}{\Gamma(...
9
votes
Accepted
Is it possible to proof a-b+b = a for all double floating-point numbers?
You can sometimes prove such results (or get counterexamples) using an SMT solver such as Z3 that supports floating point arithmetic. Here is a proof of a version of your theorem that says $|((x+y)-y)-...
9
votes
Accepted
Accurate computation of Gauss-Kuzmin entropy
It's fairly easy to evaluate, to do this expand the logs in Taylor series in $x=(k+1)^{-2}$:
$$ \log_2(1-x) = \frac{-1}{\log 2}\sum_{m\geq1}\frac{x^{m}}{m}$$
$$ \log_2(-\log_2(1-x)) = \frac{\log x}{\...
9
votes
Accepted
Fast and accurate double precision implementation of incomplete gamma function
The integral in question is also known as the Boys function, after the British chemist Samuel Francis Boys who introduced its use in the early 1950s. A few years ago, I needed to compute this function ...
8
votes
What is the best method of computing $a^{(k)}/k!$?
Njuffa already answered satisfactorily, but let me comment that dealing with large numbers does not cause loss of precision in floating-point arithmetic: the error is a relative one, corresponding to ...
6
votes
Accepted
Accuracy of finite differences
I think you probably already know all this, and maybe it's just the wording that is confusing. I'm going to rephrase what they're doing to make it more explicit. It's exactly the same calculation of ...
6
votes
Intuition for relative error for vectors
You are overthinking relative error in one-dimension, and I expect that is the source of your confusion.
If I measure the length of an ant, and I am off by 1mm, its a big deal. However, if I were ...
6
votes
Accepted
General approach to infinite sums
Note the identity for the modified Bessel functions of the first kind,
$
e^z = I_0(z) + 2 \sum_{k=1}^{\infty} I_k(z)
$
(Abramowitz and Stegun, Eq. 9.6.34, https://personal.math.ubc.ca/~cbm/aands/...
5
votes
Accepted
Adam Bashforth 4 method: how to determine starting values and stil keep the the order of accuracy
What you are looking for is called "bootstrapping". It is a common problem of all multistep ODE integrators and is discussed in many books on the topic.
Among your options are to use a lower-order ...
5
votes
What is a good definition of "accuracy to N digits"?
Short version
In scientific computing, the notion of relative error is way more popular than accuracy to $N$ digits. Whenever we present the results, we usually plot the obtained (scaled) data and ...
5
votes
Accepted
Does the IEEE-754 standard mandate that exp2 is rounded correctly?
According to [1]: "However, the IEEE-754 standard specifies nothing for elementary functions" and "Indeed, the mathematical libraries (libm) provided by operating systems do not guarantee correct ...
4
votes
Intervals where the sign of a polynomial can be computed reliably
Yes. You can compute a running error bound, i.e, a number $\mu$ such that the difference between the exact value of $y = p(x)$ and the computed value satisfies $\hat{y}$ satisfies $$|y - \hat{y}| \leq ...
4
votes
How to get a more accurate cancelation
I am not sure this is possible with the Python libraries since they are using Fortran under the hood and that can't be easily recompiled, but the Julia DifferentialEquations.jl JIT compile specializes ...
4
votes
Accepted
Accuracy gap for apparently stable solution
Stability does not necessarily imply accuracy.
I'll demonstrate this with a simple scalar ODE $y' = \lambda y$ (known as Dahlquist's test equation). This simple ODE is generally interpreted as a ...
3
votes
Accurate evaluation of the sign of a polynomial
Compensated Horner method (http://www-pequan.lip6.fr/~jmc/polycopies/Compensation-horner.pdf) has an error bound of the form
$$ |\mathrm{comphorner}(p, x) - p(x)| \leq u|p(x)| + \gamma_{2n}^2\tilde p(...
3
votes
Accepted
When writing a research article, how to deal with deviations from theoretical expectations due to numerical errors?
If you have theoretical expectations for some observables of simulations, I see two general ways of dealing with them:
You exploit them to get more accurate results, e.g., you make your algorithm use ...
3
votes
Accepted
Automatic finite differences
This is what Griewank et al. call "Piecewise linearization in secant mode", see for instance https://opus4.kobv.de/opus4-zib/files/6164/newton_secant_approx_paper.pdf. The aim of that ...
3
votes
How to find the optimum finite difference method for derivatives?
The choice of finite-difference scheme depends on several factors, such as the smoothness of your data, how uniformly-spaced the data actually is, etc. You may also want to consider just how accurate ...
2
votes
Accepted
Training accuracy improves but test set accuracy remains the same
I think you experience the implications of overtraining. From this question and this paper:
Since a neural network with a sufficient number of neurons in the hidden layer can exactly implement an ...
2
votes
Intervals where the sign of a polynomial can be computed reliably
I want to add that in addition to Carl Christian's suggestion of using a running error bound, you can also take the general relative error bound
$$ \frac{|\hat p(x)-p(x)|}{|p(x)|} \leq \gamma_{2n}\,\...
2
votes
Achieving high relative accuracy (vs. absolute accuracy) using spectral methods
So I went ahead and implemented a code in Matlab that can solve this problem using a spectral approach, utilizing a simple polynomial basis. Using a simple polynomial basis of order 20 resulted in the ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
accuracy × 66finite-difference × 15
numerics × 12
floating-point × 10
error-estimation × 7
precision × 6
matrix × 5
fluid-dynamics × 5
finite-volume × 5
convergence × 5
discretization × 5
finite-element × 4
python × 4
ode × 4
algorithms × 3
stability × 3
runge-kutta × 3
linear-algebra × 2
matlab × 2
boundary-conditions × 2
nonlinear-equations × 2
c++ × 2
interpolation × 2
integration × 2
hyperbolic-pde × 2