Questions on the numerical functions of Mathematica, implementing numerical methods and numerical computing with Mathematica.
34
votes
10answers
975 views
Can Mathematica propose an exact value based on an approximate one?
Sometimes, I use Mathematica to do some hypothesis on homeworks to make the question easier. For instance, when I have to compute big sums when $n\to\infty$ and Mathematica can't give the exact ...
33
votes
1answer
883 views
Adaptive sampling for slow to compute functions in 2D
EDIT: Although I have posted an answer based on my current progress, this in incomplete. Please see the "open issues" section in the answer.
Most plotting functions in Mathematica adjust the ...
31
votes
7answers
891 views
Updating Wagon's FindAllCrossings2D[] function
Stan Wagon's Mathematica in Action (second edition; I haven't read the third edition and I'm hoping to eventually see it), demonstrates a nifty function called ...
31
votes
2answers
550 views
Is it possible to make Mathematica reformulate an expression in a more numerically stable way?
I'm writing a numerical optimization, and I'm having a problem with an expression of the form
$$ e^{-t} (1+\mathrm{erf}(t)) $$
The overall shape of the function looks correct, but when $t$ is small, ...
28
votes
1answer
483 views
26
votes
6answers
2k views
Finding real roots of negative numbers (for example, $\sqrt[3]{-8}$)
Say I want to quickly calculate $\sqrt[3]{-8}$, to which the most obvious solution is $-2$.
When I input $\sqrt[3]{-8}$ or Power[-8, 3^-1], Mathematica gives the ...
25
votes
2answers
1k views
Efficient Langevin Equation Solver
This question is not about good algorithms for solving stochastic differential equations. It is about how to implement simple codes in Mathematica efficiently exploiting Mathematica's programming ...
21
votes
4answers
548 views
How to use NDSolve to track equilibrium?
I am looking for an extension of NDSolve where integration runs until certain variables are settled at an equilibrium. Now I have a working solution in my sleeves ...
21
votes
3answers
373 views
Computing polynomial eigenvalues in Mathematica
MATLAB offers a function polyeig for computing polynomial eigenvalues, which appear, for instance in quadratic eigenvalue problems (see here for some applications) such as:
\begin{equation}
...
20
votes
1answer
461 views
Numerics with mathematica
From time to time, I would like to use Mathematica purely numerically, e.g., plotting a function which is defined as an integral which cannot be solve analytically or a solution of a differential ...
19
votes
2answers
1k views
Why round to even integers?
According to the Mathematica help:
Round rounds numbers of the form x.5 toward the nearest even integer.
For example:
Round[{0.5, 1.5, 2.5, 3.5, 4.5}]
...
19
votes
2answers
472 views
Meaning of backtick in floating-point literal
If I compute, say, 1/3//N, Mathematica displays
0.333333
as the result.
When I copy that output to use elsewhere,
the paste ...
17
votes
1answer
252 views
Is there an NDSolve`ProcessEquations analog for NIntegrate?
NDSolve has an interface for repeatedly solving an equation with different initial conditions without having to analyze the equation and set up the solving algorithm each time. This can improve ...
17
votes
0answers
629 views
Identifying critical points of 2/3D image/cubes
Upshot
I am interested in identifying critical points of a 3D field/cubes (maxima, minima, tube-like and wall-like saddle points) and 2D field/image (maxima, minima, saddle points). I.e. the ...
16
votes
5answers
456 views
Is this the most efficient way to round approximate integers to integers while leaving other Reals untouched?
This might seem like an overly simple question, but I need to specify custom plot tick marks as integers (no trailing decimal point) if they are approximately integers, but not if they are not. Using ...
15
votes
0answers
353 views
Fast Spherical Harmonics radiative transfer
This is a rather specific question and I apologize for spamming you with some lengthy code. But it could be interesting for some reader and maybe you can help out, so please bear with me.
I am using ...
14
votes
5answers
767 views
The difference between 0. and 0
I have a function for which 0 is a special case:
f[A___, 0, B___] := 0
But since I am doing numerics, sometimes in the course ...
14
votes
4answers
271 views
How to remove duplicates from set of machine precision 2D points?
I have a set of 2D points with machine precision coordinates. I need to remove all duplicates. Performance is important.
This is the most obvious fast solution:
...
14
votes
1answer
345 views
Obtain approximate Hessian using FindMinimum
According to the documentation, when FindMinimum is told to use the method "QuasiNewton" on a unconstrained problem, it uses the ...
13
votes
3answers
299 views
Make mathematica treat $e_i^2$ as numeric
With NumericQ[symbol] = True, I can declare that a symbol is numeric. I want the expressions matching: $$e_{\text{i$\_$}?\text{IntegerQ}}^2$$ to be treated as ...
13
votes
3answers
1k views
Solving a Volterra integral equation numerically
I would like to solve for $P(t)$, in Mathematica, a Volterra integral equation of the 2nd kind.
It is:
$$P(t) = R_0(t) + \int_0^t P(t') R_0(t-t')dt'$$
I know the function $R_0$ and would ...
13
votes
1answer
341 views
What strategies can I use to evaluate a limit when Limit[] returns unevaluated
I'm trying to find the following limit using Mathematica:
$$\lim_{N\to\infty}\sum_{k=1}^N\left(\frac{k-1}{N}\right)^N$$
The problem is taken from here and is known to converge to ...
13
votes
1answer
268 views
Optimizing a Numerical Laplace Equation Solver
Laplace's Equation is an equation on a scalar in which, given the value of the scalar on the boundaries (the boundary conditions), one can determine the value of the scalar at any point in the region ...
12
votes
2answers
427 views
Higher order periodic interpolation (curve fitting)
I have a list of points in 3D, and I want to get a smooth interpolation or curve fit (it is more for illustration) of these points such that the first and second derivatives at the start and end ...
12
votes
1answer
327 views
How to guarantee that NDSolve correctly detects abrupt changes in parameters?
When using NDSolve, I often have parameters that, in most of their domain, have a constant or null variation, but that suffer from abrupt variations on a very small ...
12
votes
3answers
488 views
Strategies to avoid LessEqual::nord in NMinimize?
When using NMinimize on functions with complex intermediate expressions (but a real end result), quite often one gets the error ...
12
votes
3answers
577 views
Finding a fit to a multi-dimensioned function
I have a model function $f:\mathbb{R}^2\rightarrow\mathbb{R}^2$, and a bunch of data points for which I'd like Mathematica to fit for me. Unfortunately FindFit ...
12
votes
1answer
386 views
How to compute the inverse CDF properly?
I want to compute the CDF and inverse CDF of the hyperbolic distribution:
α = 2; β = 3/2;
x = -3;
u = N[CDF[HyperbolicDistribution[α, β, 1, 0], x], 30]
The ...
12
votes
2answers
317 views
Preventing Numerical value from being evaluated
I have searched stackoverflow (and comparable pages) for quite a while now (got redirected from there to this specialized stack), and I surrender. I am trying to evaluate an expression that is small ...
11
votes
2answers
320 views
11
votes
1answer
412 views
2D Heat equation: inconsistent boundary and initial conditions
I'm attempting to use NDSolve on a 2D boundary value problem with initial conditions. Upon running my code, I get the following message:
"NDSolve::ibcinc: Warning: Boundary and initial conditions are ...
11
votes
1answer
934 views
Parallelizing Numerical Integration in Mathematica
I have an ugly, six dimensional function that I need to integrate numerically. It works, but it currently take twelve hours to complete the calculation. Is there any good way to parallelize the ...
10
votes
6answers
435 views
Annoying display truncation of numerical results
I have a lot of data to inspect. An example of a number in my program is
123.189094
This gets displayed as
123.189
...
10
votes
6answers
2k views
About multi-root search in Mathematica for transcendental equations
I have some questions for multiroot search for transcendental equations. Is there any clever solution to find all the roots for a transcendental equation in a specific range?
Perhaps ...
10
votes
4answers
690 views
Numerical underflow for a scaled error function
I calculate scaled error function defined as
f[x_] := Erfc[x]*Exp[x^2]
but it can not calculate f[30000.]. ...
10
votes
1answer
279 views
Funny behaviour when plotting a polynomial of high degree and large coefficients
I am trying to plot a polynomial of degree 29 on the domain [0,1], with fairly large coefficients:
...
10
votes
2answers
364 views
Can Mathematica Handle Open Intervals? Interval complements?
Open Intervals
Following up on this question, I was wondering whether Mma can handle open intervals. For example, the union of the intervals, $$1<x<5$$
and $$5<x<8$$
should not ...
10
votes
1answer
218 views
Why can't I change the value of MaxRecursion in NIntegrate when integrating BesselJ?
I am trying to evaluate this integral numerically
$$
\int_0^{\infty } J_0(q R) \tanh(q) \, \mathrm{d}q
$$
for large values of $R$. This makes the integrand oscillate more quickly and Mathematica ...
10
votes
2answers
350 views
Is it possible to use the LevenbergMarquardt algorithm for fitting a black-box residual function?
I have a black-box multiargument multiparametric function of the type SRD[dataPoint_List,params_List] which accepts experimental data along with the parameters of ...
9
votes
2answers
1k views
Numerically obtaining the inverse Laplace transform of data
I have been using several Mathematica packages to do numerical inverse Laplace transforms on known (expressible in closed form) expressions, $\tilde{f}(s)$. I am now being confronted with the more ...
9
votes
2answers
197 views
Determining the default Method used in optimization and root-finding algorithms
Is it possible to extract the Method which is used in functions like NMinimize, FindRoot, ...
9
votes
1answer
938 views
What method does NDSolve use for solving PDEs?
What is NDSolve's mode of operation?
I use it to solve partial differential equations and never gave it too much thought. Recently, I came across this question. ...
9
votes
1answer
151 views
RandomReal closed on left & open on right?
I have a number of algorithms that depend on uniform random reals in half-open intervals such as $[0,1)$. In particular, I need a (pseudo) random-number generator that produces machine-precision ...
9
votes
1answer
150 views
Converting to machine precision
There are multiple ways to convert an expression to machine precision, for example:
...
8
votes
4answers
225 views
Numerical integration of a numeric data available as a nested list
I have some numerical data in the form of a list with the following structure: {...{x,y,z},...} defining a surface z=z(x,y) in a 3D space (x,y,z). The data came from a simulation, and I am ...
8
votes
1answer
233 views
Why is MainEvaluate being used when LinearSolve can be compiled?
According to this question LinearSolve can be Compiled. However, CompilePrint shows a MainEvaluate but no-warning is generated. It appears that LinearSolve is not ...
8
votes
1answer
379 views
How do I find all the solutions of three simultaneous equations within a given box?
Sometimes, one needs to find all the solutions of three simultaneous nonlinear equations in three unknowns
$$\begin{align*}f(x,y,z)&=0\\g(x,y,z)&=0\\h(x,y,z)&=0\end{align*}$$
within a ...
8
votes
1answer
885 views
Kramers-Kronig in Mathematica
I am trying to calculate the change of the refractive index from the change of the absorption coefficient using the Kramers-Kronig relations, in Mathematica.
...
8
votes
1answer
498 views
Combined numerical minimization and maximization
I want to numerically calculate the maximum of a function defined by the minimization of another function, like the following:
...
8
votes
1answer
451 views
Poisson solver using Mathematica
I am looking for some help with a Poisson solver I am writing in Mathematica. The code is quite long with Arrays plugged in, so the full details can be found at http://pastebin.com/uSrSDcW6
I am ...
