Questions tagged [numerics]

Questions on the numerical functions of Mathematica, implementing numerical methods and numerical computing with Mathematica.

Filter by
Sorted by
Tagged with
0
votes
1answer
48 views

Displaying the repeating decimal expansion of a rational number

How do I write a decimal expansion of a rational number $a/b$ with only periodic part, e.g., given $1/7=0.14285714285714285714 \ldots$, I want just $0.142857$, the periodic part of $1/7$, to be ...
0
votes
0answers
43 views

sine-Gordon equation using pseudospectral method [on hold]

I want to try this code what is the problem ? I tried this from https://reference.wolfram.com/language/tutorial/NDSolveMethodOfLines.html When i tried this i got ...
1
vote
1answer
63 views

Getting a warning that a number is too small to be represented as a normalized machine number [closed]

I have the following summations: The code: ...
0
votes
0answers
70 views

How to differentiate a function constructed through FindRoot?

I am trying to maximize a function which has as a variable another function that was solved numerically using FindRoot. My code is below.I start by defining some parameters ...
2
votes
1answer
42 views

Error with NSum : it returns NSum::nsnum: Summand (or its derivative) f[n] is not numerical at point n=17

Consider the following example (I had a lot of trouble to find a minimal working example, I think it is compactified enough now). ...
2
votes
2answers
136 views

Compute unstable integral with high precision

I want to calculate $$ \int_{\mathbb{R}^n} e^{-t_1^4-t_2^4- ...-t_n^4-(1-t_1-t_2-...-t_n)^4} \text{d}t_1 \text{d}t_2 ... \text{d}t_n $$ with the highest possible n. I tried with ...
0
votes
0answers
73 views

How to tell Mathematica to do all calculations in a notebook numerically?

I would like to tell mathematica to do all calculations numerically. I have already replaced my input by adding a dot in the end, for example : nAvg=10. But the ...
1
vote
2answers
41 views

Sum up different arrays into a new array

I have a question regarding sums in arrays. So I have the following array: ...
0
votes
1answer
48 views

Calculating the distance between two points and get direction [closed]

I am programming a molecular dynamics program with periodic boundary conditions. Here, I have a problem: I have a list of coordinates like ...
10
votes
1answer
187 views

How to calculate $\displaystyle \prod_{p}\frac{p^2+1}{p^2-1}$?

When I input $$ \prod _{p=2}^{\infty } \text{If}\left[\text{PrimeQ}[p],\frac{p^2+1}{p^2-1},1\right] $$ in Mathematica 12.0, it gives out the value $1$. The result is ridiculous, for that according to ...
1
vote
1answer
89 views

Given a function $f(t,s)$, compute $\max_{t_2\in [0,1]}\min_{t_1\in [0,1]} |f(t_1,s_1)-f(t_2,s_2)|$

Given a continuous and bounded function $f(t,s)$, $t,s\in[0,1]$, I would like to compute $$\max_{t_2\in [0,1]}\min_{t_1\in [0,1]} |f(t_1,s_1)-f(t_2,s_2)|,$$ for each numeric values of $s_1$ and $s_2$....
4
votes
2answers
61 views

Numerical equation solving with FindRoot and BandpassFilter

I have problems combining filtering of a data list and FindRoot. Here is an example: ...
2
votes
1answer
83 views

Problem with NDSolve: Maximum number of steps reached

I am using NDSolve to solving a first order autonomous system of ODEs $\dot x(t) = f(x(t))$, $x\in\mathbb R^n$ numerically for a set of initial conditions $x(0)=a,b,...
2
votes
1answer
78 views

NDSolve cannot evolve Gaussian wave packet with small width

I want to solve a 1d wave equation with initial conditions: $$ u(x,0) = f(x) = e^{-(x - x0)^2/2\sigma^2} \ \ \text{and}\\ u_t(x,0) = - f_x(x) $$ The second condition is the advection equation and ...
1
vote
2answers
148 views

NMaximize not always returning solution

This question is related to a previous question and answer here: NMinimize or NMaximize for a dynamic problem but tackles a different problem. I am trying to solve a simple linear quadratic ...
6
votes
2answers
142 views

Sorting upon the first element of a nested list and show that as numerical values

I wish to sort the below list upon the first elements: ...
0
votes
0answers
16 views

SystemException[“MemoryAllocationFailure”] with long evaluation involving FindRoot

I had earlier posted my code in a previous question, but I am reposting my code here: ...
1
vote
0answers
39 views

Exponential distribution and numerical errors?

I am working on the measure of a Curie Weiss model over a lattice $$ \mu[m] = \frac{e^{\beta N (hm + m^2)}}{\sum_z e^{\beta N (hz + z^2)}}\binom{N}{\frac{(1-m)N}{2}}2^{-N} $$ where $m\in\{-1,-1+2/N,\...
0
votes
0answers
33 views

FindRoot for a transcendental function (PolyLog)

I am trying to solve an equation involving polylog using FindRoot, I am not sure how to give the initial guess as I want to solve the equation for a variety of parameters. Here is my code: ...
0
votes
1answer
51 views

How to keep the numerical integration when an event occurs?

I'm numerically integrating the following system, f[r_] = 0.904965 - (1 + 12.7028/r^2) (1 - 2/r) dϕdλ = 1/r[λ]^2; eqc = r'[λ] == Sqrt[f[r[λ]]/(dϕdλ^2)]; with the ...
11
votes
1answer
675 views

Is there a faster way to calculate Abs[z]^2 numerically?

Here I'm not interested in accuracy (see 13614) but rather in raw speed. You'd think that for a complex machine-precision number z, calculating ...
4
votes
2answers
207 views

Underflow error General::munfl from E^x instead of Exp[x]

In contrast to earlier versions, Mathematica 11.3 and 12.0 generate lots of underflow errors from my code, e.g. ...
2
votes
1answer
64 views

Creating a mesh from a very thin layer

I have the following code which works just fine: ...
2
votes
2answers
71 views

How to check for underflow, and find a constant to correct it?

In a programme I'm running, at a certain point there's a multipplication of variables that gives underflow... For example $c=c_1\times c_2$. Is there anyway to check if that multiplication gives ...
2
votes
1answer
43 views

Find x at a given t and f(x,t) == constant from a system of coupled PDE

Is it possible to find the speed of a moving front (produced by the below code) in which modulating beta changes the speed of the front? Basically, I am trying to map the x-values of f(x,t)=0.5 ...
0
votes
0answers
26 views

Changing a Constant Based on Certain Radius

I'm trying to change my Mu based on the size of my spherical radius but cannot seem to get the code right. I've tried numerous ways but end up either with only one Mu (ex. Mu=21) in the end or code ...
3
votes
1answer
214 views

Solution of Burgers equation with some initial data

Consider the Burgers equation $$\partial_t u + \partial_x\left(u^2/2 \right) = 0, \quad u(0, x) = u_0(x).$$ eq = D[u[t, x], t] + D[u[t,x]^2/2, x] == 0 How ...
1
vote
1answer
112 views

Numerical simulation for density of strings in a ball

I am trying to numerically reproduce the Mathematica result for the density of strings in a sphere as explained here. The program is to generate random, uniformly distributed pair points on a unit ...
1
vote
1answer
42 views

How to plot even function without noticeable asymmetry

I am trying to plot a series of functions. But the picture is looking a bit asymmetric despite that the functions are even. If I try to use Geometricaltransformation function to reflect the plot that ...
2
votes
1answer
87 views

Correct syntax for working precision in functions version 12

I just recently updated from version 11.2 -> 12...there apparently are quite a few changes since 11.2. $\unicode{952}\unicode{960}$ One being how version >11.3 deal with numbers that approach zero. ...
10
votes
2answers
814 views

Why does Arg'[1. + I] return -0.5?

From the document we know that Arg[z] gives the gives the argument of the complex number z. Then how about ...
4
votes
1answer
73 views

Improving Speed of Binomial and Multinomial Random Draws

A number of users have discussed the speed of Random number generation in Mathematica. The Binomial and Multinomial random number generators in Mathematica are fast if multiple draws are needed for ...
0
votes
1answer
35 views

NDSolve outcome depends on system size?

I tried to solve a simple wave equation numerically and plot the result within the time range t=0...1. Now when I change the tmax in the NDSolve the outcome of my plot (I don't change anything else ...
0
votes
0answers
75 views

Numerical methods to solve an ODE with discontinuous coefficients

Consider the ODE $$\partial_t \Phi(t,x) = \mathbf b(\Phi(t,x)), \qquad t \in [0,T], \quad x=(x_1,x_2) \in \mathbb{R}^2$$ $$\Phi(0,x) = x, \quad x \in \mathbb R^2,$$ where $\mathbf b = (0,\chi_{\{x_1 \...
3
votes
2answers
162 views

NIntegrate on a solution of a matrix ODE

I've seen similar questions on this site but somehow the solutions there didn't manage to solve my specific problem. I have a function mat1 that takes a square $n \times n$ matrix G, and some final ...
0
votes
0answers
53 views

Plot BV functions with singular derivatives in multiple space dimension

In 1-dimensional setting, two key examples of $BV$ functions (of bounded variation) $u: \mathbb R \to \mathbb R$ are the Heaviside function, whose derivative is the Dirac delta concentrated at $0$. It ...
3
votes
2answers
746 views

How to evaluate this function?

I’m trying to evaluate y[t] = InverseFunction[ NIntegrate[Sqrt[2]/( -8+Exp[y]+2Exp[-y]), {y,0,t}]] Some of the problems I’m facing, is that i’d like to get the ...
1
vote
1answer
66 views

How to write mathematica code for Newton's Forward Difference Formula?

I want to write the Newton's Forward Difference Formula in mathematica: http://mathworld.wolfram.com/NewtonsForwardDifferenceFormula.html I know there many functions to interpolate data in ...
5
votes
2answers
378 views

Numerical methods to solve a continuity equation

What numerical methods can be used to study the initial value problem for the continuity equation where $ u = u(t, x) $ $$ u_t + \nabla\cdot(\boldsymbol b u) = 0, \qquad t \in [0,T], \quad x=(x_1,x_2)...
3
votes
1answer
197 views

Boundary conditions are not satisfied with NDSolve

I want to study the time evolution of a small perturbation around the static solution of the following Wave Equation $$ -\partial_t^2 v(t,r) + \partial_r^2v(t,r) + \frac{2}{r}\partial_r v(t,r) = \...
0
votes
1answer
89 views

An example of symmetric, real entry matrix with non-real eigenvalues, according to Mathematica. Is this a bug?

The following matrix is symmetric and all entries are real, ...
4
votes
1answer
449 views

How to prevent mathematica rounding extremely small numbers to zero?

I have a function that, while the maths itself is unimportant, at certain values it results in a very large number multiplying a very small number. E.g. 10^450000 * 10^-449998. As you can see, this ...
0
votes
0answers
28 views

Maximum likelihood method computational details

I am currently using the command FindDistributionParameters to estimate the parameters of a StableDistribution via Maximum Likelihood using Mathematica 11. As there are different MLE methods for ...
0
votes
0answers
39 views

Can I use countroots with an Interpolating Function?

I want to count the number of roots of an interpolating function that is the result of a system of differential equations (that were solved numerically using NDSolve...
0
votes
2answers
81 views

How to find maximum from list or table

I have some result in list form and after I build the graph I have: As you can see on the graph there is a spurious peak at the beginning. So when I tried to find maximum peak, I receive value of ...
1
vote
3answers
78 views

When should one write integer numbers with a decimal?

I often see different solutions where users have taken advantage of how Mathematica handles numbers differently. I.e. when is it appropriate to use a decimal point in a calculation? Can someone ...
6
votes
2answers
256 views

Specific numerical eigenfunctions of Helmholtz equation in 3D for ellipsoids

I am trying to compute the eigenfunctions of an oblate spheroid (a=75 cm and b=60 cm) using Mathematica's FEM package and Chris' answer from here. Specifically, I am looking for eigenfrequencies ...
0
votes
0answers
47 views

Why doesn't SetPrecision give me the precision I ask for? [duplicate]

I'm dealing with a problem requires a precision of 50 digitals after the decimal point. However, I got the following value when doing so: I don't know what's going on here, ain't it 0.09 with other ...
2
votes
2answers
143 views

What is the fastest way of doing one integral in Mathematica?

I want to compute the following numerical integral in Mathematica $\int_0^L dy \int_0^y d \bar{y} f(y,\bar{y}),$ where $f(y,\bar{y})$ is a very complicated function. I show my code below where the ...