Questions tagged [numerical-methods]

Algorithms which solve mathematical problems by means of numerical approximation (as opposed to symbolic computation).

Numerical methods include the study of algorithms that use numerical approximation (as opposed to general symbolic manipulations) for the problems of mathematical analysis (as distinguished from discrete mathematics). Numerical methods naturally find applications in all fields of science and engineering, and include implementations of many important aspects of computation including: solving ordinary and partial differential equations, numerical linear algebra, stochastic differential equations, Markov chains, and so forth.

Numerical methods use several approaches to calculate observables. For example, iterative methods that form successive approximations that converge to the exact solution only in a limit. A convergence test, often involving the residual, is specified in order to decide when a sufficiently accurate solution has (hopefully) been found. Examples include Newton's method, the bisection method, and Jacobi iteration. Another example is the use of discretization, a procedure that is used when continuous problems must sometimes be replaced by a discrete problem whose solution is known to approximate that of the continuous problem.

The field of numerical methods includes many sub-disciplines. Some of the major ones are:

  • Computing values of functions

  • Interpolation, extrapolation, and regression

  • Solving equations and systems of equations

  • Solving eigenvalue or singular value problems

  • Optimization

  • Evaluating integrals

  • Differential equations

2104 questions
5
votes
1 answer

How can I use the Linesearches.jl module in Julia independent of Optim.jl?

I have an implementation of L-BFGS, and would like to call the line-search from LineSearches.jl to compare. However, the documentation is quite sparse and focuses only on the use of Linesearches.jl in the context of Optim.jl. I cannot find any…
5
votes
3 answers

Runge-Kutta algorithm C++

Below is my 4th order Runge-Kutta algorithm to solve a first order ODE. I am checking it against the wikipedia example found here to solve: \frac{dx}{dt} = tan(x) + 1 Unfortunately it is out by a little bit. I have toyed around for a long while,…
PeterSM
  • 143
  • 2
  • 6
5
votes
4 answers

taking log of very small values using numpy/scipy in Python

I have an Nx1 array that corresponds to a probability distribution, i.e. the sum of the elements sums to 1. This is represented as a regular numpy array. Since N might be relatively large, e.g. 10 or 20, many of the individual elements are pretty…
user248237
5
votes
8 answers

The fastest way to save large data to a file

I do some numerical calculation in Java, C# and C++. Some of them save a lot of data (to the text file). What is the fastest way to do it? C++. ofstream file; file.open(plik); for(int i=0;i<251;i++){ for(int j=0;j<81;j++) …
Lukasz Madon
  • 14,664
  • 14
  • 64
  • 108
5
votes
2 answers

Steepest descent to find the solution to a linear system with a Hilbert matrix

I am using the method of steepest descent to figure out the solution to a linear system with a 5x5 Hilbert matrix. I believe the code is fine in the regard that it gives me the right answer. My problem is that: I think it is taking too many…
5
votes
1 answer

2D boundary conditions in Fortran

Hi I am having trouble with imposing boundary conditions on a 2 dimensional discretization problem in fortran. My discretization grid is a 2 dimensional square that goes from -L to L in x,y directions. I want to impose the boundary condition such…
5
votes
2 answers

JavaScript Math.sqrt performance

Through code profiling, I have found the Math.sqrt function specifically to be a major bottleneck in a large doubly-nested loop that runs every timestep in my program. Is there any way to improve its performance? Should I inline some kind of…
user76284
  • 1,269
  • 14
  • 29
5
votes
1 answer

Comparison Boost.Odeint vs Scipy.integrate.odeint?

I have recently stumpled upon the boost.odeint library and I am surprised about the number of possibilities and configurability. However, having used scipy.integrate.odeint extensively (which is essentially a wrapper to ODEPACK in fortran) I…
varantir
  • 6,624
  • 6
  • 36
  • 57
5
votes
1 answer

Derivatives blow up in python

I am trying to find higher order derivatives of a dataset (x,y). x and y are 1D arrays of length N. Let's say I generate them as : xder0=np.linspace(0,10,1000) yder0=np.sin(xder0) I define the derivative function which takes in 2 array (x,y) and…
user3440489
  • 259
  • 1
  • 4
  • 13
5
votes
3 answers

How to compute exact complexity of an algorithm?

Without resorting to asymptotic notation, is tedious step counting the only way to get the time complexity of an algorithm? And without step count of each line of code can we arrive at a big-O representation of any program? Details: trying to find…
AruniRC
  • 5,070
  • 7
  • 43
  • 73
5
votes
1 answer

Avoid underflow using exp and minimum positive float128 in numpy

I am trying to calculate the following ratio: w(i) / (sum(w(j)) where w are updated using an exponential decreasing function, i.e. w(i) = w(i) * exp(-k), k being a positive parameter. All the numbers are non-negative. This ratio is then used to a…
5
votes
4 answers

Construct an array spacing proportional to a function or other array

I have a function (f : black line) which varies sharply in a specific, small region (derivative f' : blue line, and second derivative f'' : red line). I would like to integrate this function numerically, and if I distribution points evenly (in…
DilithiumMatrix
  • 17,795
  • 22
  • 77
  • 119
5
votes
1 answer

how to improve this adaptive trapezoidal rule?

I have attempted an exercise from the computational physics written by Newman and written the following code for an adaptive trapezoidal rule. When the error estimate of each slide is larger than the permitted value, it divides that portion into two…
5
votes
2 answers

N body simulation in C#

I'm trying to implement an N body simulation in C# using either Runge Kutta 4 or Velocity Verlet integration algorithms. Before I move to a bigger number of particles, I wanted to test the simulation by modeling the earth's orbit around the sun,…
fbartolic
  • 403
  • 1
  • 5
  • 18
5
votes
3 answers

How to calculate machine epsilon in MATLAB?

I need to find the machine epsilon and I am doing the following: eps = 1; while 1.0 + eps > 1.0 do eps = eps /2; end However, it shows me this: Undefined function or variable 'do'. Error in epsilon (line 3) while 1.0 + eps > 1.0 do What…
Vzqivan
  • 361
  • 3
  • 6
  • 16