Maxim Umansky
  • Member for 8 years, 8 months
  • Last seen this week
  • Livermore, CA
Computing numeric derivative via FFT - SciPy
Accepted answer
8 votes

FFT returns a complex array that has the same dimensions as the input array. The output array is ordered as follows: Element 0 contains the zero frequency component, F0. The array element F1 ...

View answer
General approach to infinite sums
Accepted answer
6 votes

Note the identity for the modified Bessel functions of the first kind, $ e^z = I_0(z) + 2 \sum_{k=1}^{\infty} I_k(z) $ (Abramowitz and Stegun, Eq. 9.6.34, https://personal.math.ubc.ca/~cbm/aands/...

View answer
How to solve the integral-like energy equation with Sagdeev potential numerically in Python?
Accepted answer
5 votes

A simple approach here would be to use the shooting method, by integrating from $\xi$=0 to infinity (some large value) the ODE written as $ \frac{d}{d\xi} \phi = \sqrt{-2 S(\phi)} $ Due to the ...

View answer
Solving system of nonlinear vector functions
Accepted answer
5 votes

If you have a single vector equation $\vec{F}(\vec{x})=0$ then you solve it by representing that state vector $\vec{x}$ as a set of amplitudes $[x_0,x_1,...,x_{n-1}]$ after discretization by your ...

View answer
Computing second derivatives with Neumann boundary condition
4 votes

Let's do it for the left boundary point $x=a$, and for simplicity assume $a=0$. To implement $u_x$=0 at $x$=0, assume the function $u(x)$ is even in the vicinity of $x$=0, and let the grid points be $...

View answer
Computing infinite series with iterated functions
4 votes

There is no finite limit for this series sum. Note that for each $n$ the function $f_n$ is positive definite, $f_n(x) > 0$ within the semi-open interval $(0,\pi]$, and we can construct the lower ...

View answer
Use Monte Carlo integration to compute the volume and centre of mass in Python
Accepted answer
4 votes

Here is a corrected and slightly improved code, set up here for calculation of the full torus volume to verify the result. import numpy as np from scipy import random def func(x,y,z): return x**...

View answer
Why is $1/r^2$ force law giving spiral trajectory?
Accepted answer
4 votes

The correct dynamic equations in the polar coordinates should be $ \dot{v_r} = \omega^2 r - \alpha/r^2 \\ \dot{\omega} = - 2 v_r \omega /r\\ \dot{\theta} = \omega \\ \dot{r} = v_r $ Here is the ...

View answer
Changing variables in integral to avoid infinity
4 votes

You are almost there, just put $t$ under the square root, and it will become $ \displaystyle\int_0^{1/1095} {\frac{dt}{\sqrt{(1+644.153t)(4.17 \cdot 10^{-5} + 0.145 t)}}}, $ which eliminates the ...

View answer
Finite difference method (diffusion equation) for 3D spherical case
4 votes

An elegant approach to avoid singularities of this type was proposed in Journal of Computational Physics, Volume 124, Issue 1, 1 March 1996, Pages 93–114 'The “Cubed Sphere”: A New Method for the ...

View answer
How to solve an advection-diffusion equation
4 votes

Well, you can use Crank-Nicolson here but then you'll have to construct and solve a linear system for each time-step. That's easy to do but it would be much easier to use an ODE integrator that is ...

View answer
Polynomial interpolation on a regular hexagon
3 votes

Let's use the polar coordinates ($\rho,\theta$), then for the six vertices of the regular hexagon defined by $\rho$=1 and polar angles $\theta_i$ there are the following equations $ f(\theta_i) = a_0 ...

View answer
How to compare 2D vector fields and minimize the difference?
Accepted answer
3 votes

We consider two thin infinite straight parallel wires at distance $2 a$ apart and carrying equal currents $I$ in opposite directions. We need to find an approximate ...

View answer
Dividing functions over a wide range-
3 votes

Just take the log of your function, and then take the derivative of it. If the actual function is indeed positive definite as in the example then it is identically the same as the quotient that we ...

View answer
Calculating the Strange Attractor of the Duffing Oscillator in C++
Accepted answer
3 votes

For debugging the code, there is a set of analytic solutions here for several reduced models corresponding to subsets of terms on the right-hand side. These analytic solutions have to be reproduced by ...

View answer
Implementing structured grid boundary conditions using NumPy arrays?
Accepted answer
3 votes

The Numpy function $roll$ performs periodic shift of an array. Using it, the explicit time step for your PDE in a periodic domain can be simply implemented like this: u = u - (1/2)*(c*dt/dx)*(np.roll(...

View answer
Solving PDE with spatial and temporal derivatives on left hand side
3 votes

The equation is $\partial_{t} \psi = \partial_{x} F(\phi)$ where $\psi = \partial_x \phi$ The time-integration can be done, e.g., by explicit time-stepping: $\psi^{j+1}_i = \psi^j_i + \frac{\tau}{2 ...

View answer
Request algorithm recommomendation for 2D generalised Poisson solution
3 votes

A good way to approach this is by using existing powerful numerical packages such as PETSc. Look for PETSc examples of solving the Poisson equation, and that will be a good starting point.

View answer
Earth and Moon computer simulation
3 votes

For this type of problem, the leapfrog time-integration method is a good choice, see details here.

View answer
Finding the source of numerical instability in a electrostatic problem solved by conformal mapping
Accepted answer
2 votes

The cause of the numerical glitch has probably something to do with poor convergence of some series involved in the conformal map calculation for a particular location. However, here is how to use one ...

View answer
How do you find the Jacobian matrix of a coordinate transformation given only dynamical data points?
Accepted answer
2 votes

Let's consider a 2D case, with two coordinates $X_1, X_2$ and two derived quantities $Q_1, Q_2$. Using index 0 for a point where the partial derivatives are sought, and indices i={1,2,...} for some ...

View answer
nquad Integration in SciPy
Accepted answer
2 votes

Assuming it is the $w$ variable that has the range $[0,1-x]$ from scipy.integrate import nquad def func(w,x,y,z): return w+y def range_z(): return [0,1] def range_y(z): return [0,1] ...

View answer
Tool to compare if two logical expressions are same!
2 votes

Here is not exactly a tool but a convenient way to compare logical expressions graphically. Use electric circuits to represent your Boolean expressions: each resistor can be open gate (F) or closed ...

View answer
Calculating Error for Poisson Equation using Successive Over-Relaxation technique, Python
2 votes

This formula is correct on uniform grid (even for $\omega \neq $1 although convergence depends on $\omega$): $T[1:-1,1:-1] = \\ (1-w)*Tn[1:-1, 1:-1] \\ + \\ w*0.25*(Tn[1:-1, 2:] + Tn[1:-1, :-2] + Tn[2:...

View answer
In a dynamical system, what might be a good reason why periodicity in an object's velocities is important?
2 votes

If a certain velocity component is periodic with period $\tau$ that means that the corresponding coordinate, as a function of time, is a sum of a linear function and a periodic function with the same ...

View answer
Finite-difference software for solving custom equations
2 votes

The BOUT++ project http://boutproject.github.io offers a set of tools for finite-difference solution of systems of PDEs, primarily targeting fluid dynamics and plasma physics but not limited to those ...

View answer
Solve wave equation with discontinuous coefficients numerically?
Accepted answer
2 votes

Here is a brute force solution that would work no matter what is the discontinuity and nonlinearity in $c(x,t)$. Write your PDE as a system of two: $ \dot{y}=z\\ \dot{z}=c^2(x,t) y_{xx} $ Now, ...

View answer
Numerical solution of high-dimensional integral involving positive-part function
2 votes

Let's consider the integral in 2D. Note that the domain where $f(x_1,x_2) = x_1 + x_2 - K$ is positive lies to the right of the dashed line $x_1+x_2=K$ in the sketch, so to account for the positive ...

View answer
Issue solving nonlinear equation containing a quotient
2 votes

We can rewrite the equation as $ \frac{-2 f f'}{(1+f^2)^2} = \frac{f}{1+f^2} $ which reduces to $ f' = - \frac{1+f^2}{2} $ The latter does not have $1+f^2$ in the denominator, so it should not have ...

View answer
Eigenvalue-like problem with coupled ODEs
2 votes

Assume the equations are discretized on the $\tau$ grid, and introduce several column-vectors, using the notation where the superscript stands for the grid point index i $\in$ [1,...,n]. $\vec{\tau}=\...

View answer