# Questions tagged [python]

A general purpose high-level programming language that emphasizes ease of code syntax and readability.

746 questions
Filter by
Sorted by
Tagged with
172 views

### How to solve the integral-like energy equation with Sagdeev potential numerically in Python?

I am trying to numerically solve equation (6) of Lakhina 2021 in Python. The equation is $$\frac{1}{2}\left(\frac{d \phi}{d\xi}\right)^2 + S(\phi, M) = 0\, .$$ The Sagdeev potential expression is ...
231 views

### Convolute a gaussian kernel with a large array of off-grid centroids without looping? (how to make "A Thousand (Gaussian) Points of Light" )

For a finite object size diffraction simulator, I need to generate arrays which are the sum of thousands of instances of a Gaussian (or other) 2D kernel at centroids that will not fall in any ...
2k views

### Scipy OdeInt solver with Neumann boundary conditions

I'm using scipy.odeint to solve Fisher-Kolmogorov equation: \begin{equation} u_t = u_{xx}+u(1-u) \end{equation} The code can be found here. From Ablowitz and ...
237 views

### High frequency noise at solving diffusion equation

I'm trying to simulate a simple diffusion based on Fick's 2nd law. ...
102 views

### Compute $tr(A^TBC)$ in Python

I have to compute the trace of the product between three matrices $A,B,C$ in python, i.e. I have to compute $tr(A^TBC)$ and I was wondering what was a good way to do it in Python(here $A^T$ is the ...
176 views

### Solving a Boundary Value Question $\frac{d^2y}{dx^2}=y\cos(x)+\frac{\sin(x)}{x^2+2}$ using Python

I'm looking to solve this boundary value question using the shooting method! $$\frac{d^2y}{dx^2}=y\cos(x)+\frac{\sin(x)}{x^2+2}$$ given the initial values: $$y'(x=-1)=-1\\y'(x=5)=0$$ I'm aware of ...
193 views

7k views

### Python Vectorizing a Function Returning an Array

I have the following function that has been vectorized so that for every element in input array t, an array is output: ...
285 views

### How to separate text from the paper on a black and white page?

I tried to discretize an image into black and white and came into some difficult. The difference between the letters and paper is pretty clear to our eyes: However a simple thresholding trick doesn'...
2k views

### Hyperbolic Equation PDE (Python)

I'm trying to solve the following first order hyperbolic PDE problem using method of lines: Hyperbolic Equation: $u_t = -u_x$ with initial condition: $u(0,x) = 0, 0 < x < 1$ boundary condition: ...
105 views

### Lanczos algorithm for finding top eigenvalues of a matrix sum

I am trying to find the top k leading eigenvalues of a NumPy matrix (using python dot product notation) L@L + a*X@X.T, where $L$ ...
430 views

### Why is 'scipy.sparse.linalg.spilu' less efficient than 'scipy.linalg.lu' for sparse matrix?

I have a matrix B which is sparse and try to utilize a function scipy.sparse.linalg.spilu specialized for sparse matrix to ...
151 views

### Suggestions for scientific computing projects to undertake to sharpen core skills

Currently I am completing all exercises in books like "Introduction to Python for Science and Engineering, David Pine" and "Guid to Scientific Computing in C++, Pitt-Francis, Whitley". I am looking ...
269 views

### Solving ODE with "Jumpy" Coefficients

I'm numerically solving a linear coupled ODE of the form $$y^{\prime}(t) = \hat{M}(t)y(t)=\left[\begin{array}{cc}0& A(t)\\ B(t)& 0\end{array}\right]y(t),$$ and the difficulty I'm running into ...
331 views

### Chebyshev differentiation via FFT with a domain [a,b]

I want to ask something about Chebyshev differentiation via FFT, which can be used to obtain with spectral accuracy the derivative of a smooth function. See for instance this code in python, which ...
1k views

### How to transform this SOCP to the format required by cvxopt

I'm new to SOCP and want to try to get familiar with the format and how to solve it with cvxopt in python. However, for a simple toy example I'm struggling to get ...
3k views

2k views

### Averaging scattered data

I have multiple sets of measured data that can easily be visualized using a scatter plot (red and black points in the figure). If my measurements were perfect, the red and black points should lie on a ...
144 views

### How to get a more accurate cancelation

I shall try to get to the point, so let me know if there is something left and you need more details. I am solving a couple of equations that are not coupled explicitly, but their corresponding ...
301 views

### Fast nonzero indices per row/column for (sparse) 2D numpy array

I am looking for the fastest way to obtain a list of the nonzero indices of a 2D array per row and per column. The following is a working piece of code: ...
917 views

686 views

### Python environments for AMG and Gauss Seidel as solvers instead of preconditioners

I am working on block preconditioning and seemingly it is common to write customised Krylov solvers for them. Within each solver, the individual block linear system with preconditioners are ...
655 views

### Simple Runge-Kutta Scheme for nonlinear PDE

I am new to this community as well as to scientific programming. I programmed a simple 4th order Runge-Kutta for the 1-D Cahn-Hilliard Equation for some first simple calculations on pattern forming ...
792 views

### My calculated laser pulse duration is too large. Where am I wrong?

I am currently writing a small Python script to estimate the pulse duration from the optical spectrum. At the end, the idea is to observe the effects of the spectral phase on the pulse duration and ...
3k views

### Solving Advection (Convection) - Diffusion - Reaction Partial Differential Equation in Python

I am looking for library written in Python which will enable me to solve the coupled nonlinear equations which looks like: I need the library which will enable me to couple this solver to other ...
1k views

### Finding eigenvalues of a complex symmetric tridiagonal matrix

I am trying to find specific eigenvalues and -vectors of a large complex symmetric tridiagonal matrix (at least 10000x10000, and ideally larger). I know roughly which eigenvalues I am looking for, so ...
I have a set of dates, position angles ($\theta$) and angular separations ($\rho$) for visual binary star. For example: ...
I am trying to solve the Poisson Equation $\frac{\partial^2 T}{\partial x^2} + \frac{\partial^2 T}{\partial y^2} = 32(x(x-1) + y(y-1))$ for a 61x61 grid using Python3 with boundary conditions being \$T=...