In the mathematical subfield of numerical analysis, numerical stability is a generally desirable property of numerical algorithms. The precise definition of stability depends on the context. One is numerical linear algebra and the other is algorithms for solving ordinary and partial differential equations by discrete approximation.
Questions tagged [numerical-stability]
104 questions
1
vote
0 answers
C floating point arithmetic: multiple wrong answers
I'm running into a numerical issue in a large C programming project. (This is statistical research, not homework for a class). One step involves calculating sqrt(x^2 + y) - x, which I need to be positive, but sometimes I get sqrt(x^2 + y) - x < 0…

landau
- 5,636
- 1
- 22
- 50
1
vote
2 answers
2nd order centered finite-difference approximation
This question may sound mathematical, but it's more of a programming question related to discretization, so I decided to ask it here.
The problem is to find a 2nd order finite difference approximation of the partial derivative uxy, where u is a…

Abhranil Das
- 5,702
- 6
- 35
- 42
1
vote
1 answer
OLS in R - lm() giving a different answer to matrix calculation
I was playing around with doing a manual calculation for the OLS estimators using linear algebra in R and I got a different answer to R's inbuilt regression function lm(). Would anyone be able to tell me why there is a difference? Is R not…

1212__Hello
- 545
- 1
- 6
- 13
1
vote
1 answer
Stabilizing Infrared Distance Sensor Output Values
I'm reading infrared Sharp distance sensors:
http://www.robofun.ro/senzori/infrarosu/senzor_sharp_%20GP2D120XJ00F
With the reading I'm commanding a servo to direct the robot along a wall, a pretty simple map and write code.
The problem I'm having is…

Eugen
- 1,537
- 7
- 29
- 57
0
votes
0 answers
Iteration and Vectorization return different results
I am trying to vectorize the Brown function, which is evaluated over the range (-1,4). S (vectorized) and sigma (iterative) should therefore be equal, which they are for most input arrays I have tested, i.e. the commented a, but not for the…

Daniel von Eschwege
- 481
- 1
- 4
- 10
0
votes
1 answer
What Numerical Stability conditioning is this algorithm using for Gaussian-elimination matrix inversion?
import numpy as np
def MATINV(N, A):
'''
A = [B | D]
returns
A = [I | B^-1 * D]
if A[:,:N] \= eye(N)
then deter(B) == 0
N - number of rows (N <= number of columns)
BTRY - largest value in a row
…

Nick Brady
- 107
- 8
0
votes
1 answer
Which number can computers retain better: `256,007` or `.000333`
I've always assumed that 256,007 would take up less space and be subject to less error than a number like .000333.
For context of the question, in an engineering course we're supposed to show how LU decomposition with pivoting is more numerically…

financial_physician
- 1,672
- 1
- 14
- 34
0
votes
0 answers
Numerically stable normalizing for vectors of small magnitudes
The context of the problem is that I have a resnet model in Jax (basically NumPy), and I take the gradient of an image with respect to its class prediction. This gives me a gradient vector, g, which I then want to normalize. The trouble is, the…
0
votes
1 answer
How can I compute (exp(t) - 1)/t in a numerically stable way?
The expression (exp(t) - 1)/t converges to 1 as t tends to 0. However, when computed numerically, we get a different story:
In [19]: (exp(10**(-12)) - 1) * (10**12)
Out[19]: 1.000088900582341
In [20]:…

Jack M
- 4,769
- 6
- 43
- 67
0
votes
0 answers
Is computing the mean numerically more robust to digit cancellation than computing the sum?
Consider the following example, executed in Matlab:
x = linspace(-pi, pi, 10^4);
x_R = chop(x, 3);
y = sin(x);
y_R = sin(x_R);
s = sum(y);
s_R = sum(y_R);
abs_err_sum = abs(s_R - s);
rel_err_sum = abs_err_sum/abs(s);
m = mean(y);
m_R =…

astros
- 1
- 2
0
votes
0 answers
The numerical stability of orient operation of three points in a plain
The following photo is a part of a paper(Quicker than Quickhull by Nam-Du ̃ng Hoang et al) and it is about the orient operator of three points in a plain that uses the cross-product.
It is said that the numerical stability of (4) is worse than (2)…

Q123
- 319
- 5
- 16
0
votes
1 answer
Numerical issues for alternative way to compute (squared) euclidean distance
I want to compute the squared euclidean in a fast way, as described here:
What is the fastest way to compute an RBF kernel in python?
Note1: I am only interested in the distance, not the RBF kernel.
Note2: I am neglecting numexpr here and only use…

no_use123
- 294
- 3
- 12
0
votes
0 answers
How do I test my code for numerical stability?
I have the following method of calculating the mean and standard deviation of a stream of numbers
import numpy as np
class RunningStatisticsVar:
def __init__(self, ddof=0):
self.mean = 0
self.var = 0
self.std = 0
…

Mate de Vita
- 1,102
- 12
- 32
0
votes
0 answers
Keras: loss fluctuates between inf and number
I am working on a Keras model with a custom loss function provided by a Mixture Density Network final layer (the loss tries to minimize the negative log likelihood of some Gaussian models).
What confuses me is the loss will sometimes hit an epoch in…

duhaime
- 25,611
- 17
- 169
- 224
0
votes
1 answer
What is the worst case error for (a - b) + b?
When evaluating with IEEE 754 floating point numbers a and b, what is the worst case error in terms of the magnitude of a and b of the sum (a - b) + b? How close to a can I expect that to be?

Neil G
- 32,138
- 39
- 156
- 257