Questions tagged [numerical]

This tag is for questions concerning problems using numbers which either cannot be exactly solved, or where the exact solution may be much more difficult to acquire than by using numerical methods.

This tag is for questions concerning problems using numbers which either cannot be exactly solved, or where the exact solution may be much more difficult to acquire than by using numerical methods.

It includes questions about algorithms, precision and accuracy of underlying numbers, advantages and disadvantages of several methods, error propagation, problems with the underlying numbers and data structures.

508 questions
22
votes
1 answer

Are the character digits ['0'..'9'] required to have contiguous numeric values?

Must a C++ implementation set the chars '0'-'9' to have contiguous numeric values, i.e. so that: '0' -> 0+n '1' -> 1+n m -> m+n '9' -> 9+n I cannot find it mentioned in the documentation of isdigit ([classification] (22.3.3.1 Character…
Sebastian Mach
  • 38,570
  • 8
  • 95
  • 130
22
votes
10 answers

Derivatives in C/C++?

I have some expressions such as x^2+y^2 that I'd like to use for some math calculations. One of the things I'd like to do is to take partial derivatives of the expressions. So if f(x,y) = x^2 + y^2 then the partial of f with respect to x would be…
alanc10n
  • 4,897
  • 7
  • 36
  • 41
22
votes
3 answers

Round number to specified number of digits

Is there a simple function to round a Double or Float to a specified number of digits? I've searched here and on Hoogle (for (Fractional a) => Int -> a -> a), but haven't found anything.
amindfv
  • 8,438
  • 5
  • 36
  • 58
20
votes
4 answers

What is the limit of the Value Type BigInteger in C#?

As described in MSDN BigInteger is : An immutable type that represents an arbitrarily large integer whose value in theory has no upper or lower bounds. As I can see BigInteger is a ValueType, as much as I know, a ValueType must have a maximum…
AymenDaoudi
  • 7,811
  • 9
  • 52
  • 84
20
votes
12 answers

Test if a floating point number is an integer

This code works (C# 3) double d; if(d == (double)(int)d) ...; Is there a better way to do this? For extraneous reasons I want to avoid the double cast so; what nice ways exist other than this? (even if they aren't as good) Note: Several people…
BCS
  • 75,627
  • 68
  • 187
  • 294
19
votes
4 answers

Least Squares C# library

I am looking to perform a polynomial least squares regression and am looking for a C# library to do the calculations for me. I pass in the data points and the degree of polynomal (2nd order, 3rd order, etc) and it returns either the C0, C1, C2…
Robert Wilkinson
  • 1,199
  • 1
  • 13
  • 23
19
votes
4 answers

Javascript to convert string to number?

var str = '0.25'; How to convert the above to 0.25?
user198729
  • 61,774
  • 108
  • 250
  • 348
18
votes
10 answers

Generate letters to represent number using ruby?

I would like to generate a sequence of letters i.e. "A", "DE" "GJE", etc. that correspond to a number. The first 26 are pretty easy so 3 returns "C", 26 returns "Z", and 27 would return "AA", 28 "AB", and so on. The thing I can't quite figure out…
rmontgomery429
  • 14,660
  • 17
  • 61
  • 66
14
votes
4 answers

Which numerical library to use for porting from Matlab to C++?

I am currently prototyping some algorithms in Matlab that rely on matrix, DSP, statistics and image analysis functionality. Some examples of what I may need: eigenvectors convolution in 2D and 3D FFT Short Time Fourier Transform Hilbert…
Andy
  • 3,251
  • 4
  • 32
  • 53
13
votes
2 answers

Extract contours from ContourPlot in Mathematica

I have a function f(x,y) of two variables, of which I need to know the location of the curves at which it crosses zero. ContourPlot does that very efficiently (that is: it uses clever multi-grid methods, not just a brute force fine-grained scan) but…
Kasper Peeters
  • 1,580
  • 2
  • 18
  • 37
13
votes
3 answers

Fastest 128 bit integer library

I am working on a CPU-heavy numerical computation app. Without going into many details, it's a computational math research project that involves computing a certain function f(x) for large integer x. Right now everything is implemented in C++ in…
Eugene Smith
  • 9,126
  • 6
  • 36
  • 40
13
votes
9 answers

How to use TDD correctly to implement a numerical method?

I am trying to use Test Driven Development to implement my signal processing library. But I have a little doubt: Assume I am trying to implement a sine method (I'm not): Write the test (pseudo-code) assertEqual(0, sine(0)) Write the first…
Jader Dias
  • 88,211
  • 155
  • 421
  • 625
13
votes
1 answer

How to generate good code coverage of floating-point logic?

I am hand-crafting new code. I'd like to make sure I leave no stone unturned. Is there anything specific I can do beyond specifying Code Contracts to guide Pex so it produces good coverage in numerically-intensive code? Try searching…
GregC
  • 7,737
  • 2
  • 53
  • 67
12
votes
5 answers

What's a good way to add a large number of small floats together?

Say you have 100000000 32-bit floating point values in an array, and each of these floats has a value between 0.0 and 1.0. If you tried to sum them all up like this result = 0.0; for (i = 0; i < 100000000; i++) { result += array[i]; } you'd run…
splicer
  • 5,344
  • 4
  • 42
  • 47
12
votes
2 answers

How do I approximate the Jacobian and Hessian of a function numerically?

I have a function in Python: def f(x): return x[0]**3 + x[1]**2 + 7 # Actually more than this. # No analytical expression It's a scalar valued function of a vector. How can I approximate the Jacobian and Hessian of this function in…
nickponline
  • 25,354
  • 32
  • 99
  • 167
1
2
3
33 34