# Tag Info

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'...
• 12.3k
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}}...
• 725

### 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) .$$...
• 12.3k

### 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 ...
• 11.5k

### Matrix multiplication accuracy Matlab vs Python

Here is R1, as computed in MATLAB: ...
• 2,232
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: ...
• 1,895
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 (@...
• 1,340
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 ...
• 1,895
Accepted

• 11.4k
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 ...
• 1,895

### 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 ...
• 11.5k

### Unexpected result when summing sorted (and unsorted) positive floating point numbers

Very interesting problem! I might have a partial answer. To start, I replicated a simple C++ demo that can reproduce the effect ...
• 1,008

### 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 ...
• 171
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/...
• 2,575

### 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 ...
• 8,672
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 ...
• 2,920
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 ...
• 55.7k

### 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 ...
• 12.3k

• 11.4k
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 ...
• 2,022
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 ...
• 6,109

### 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 ...
• 211

### Accelerating convergence of a generalized continued fraction

The series that converges to $\ln(2)$ appears to be suitable for Cohen-Villegas-Zagier acceleration [PDF]. This is an acceleration technique for alternating series, but continued fractions with ...
If you are interested in comparing two integrators solve $$\frac{dq}{dt} = p \\ \frac{dp}{dt} = -q$$ with initial values $(q,p) = (1,0)$ and $dt = 0.1$ for both of them. Then plot the errors ...