Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [python]

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

0
votes
0answers
29 views

Solve system of polynomial equations with Python

I have 5 at most 4th order polynomials in 5 variables, $$p_i(x_1,x_2,x_3,x_4,x_5) \qquad i = 1, \ldots, 5$$ where all coefficients are either rational or floating point. I'd would like to get the ...
1
vote
0answers
30 views

Algebraic recursion of Hermite polynomials in SymPy [on hold]

I want to obtain the algebraic values of, for example, Hermite polynomials using SciPy but in a recursive manner. Using Maple, for example, these can be defined as ...
0
votes
1answer
12 views

Numpy: How to permute array into indices of larger array? [closed]

I have an array of length L with N zeros, and L-N non-zero values. I have another array of length N. I would like to put the values of the shorter array into the positions of the longer array which ...
0
votes
1answer
60 views

Solving advection equation - periodic conditions - using roll python function [on hold]

The original post was on stackoverflow : I transfert it here. I have to solve numerically the advection equation with periodic boundaries conditions : u(t,0) = u(t,L) with L the length of system to ...
2
votes
0answers
52 views

2d wave equation with finite differences blowing up

I am (naively) trying to solve the 2d wave equation with finite differences. But the system blows up instantly. For simplicity I set the constant $c=1$, then I am left with $$\Delta u =u_{tt}.$$ I ...
0
votes
1answer
40 views

Applying neumann boundary conditions to diffusion equation solution in python [duplicate]

For the diffusion equation $$ \frac{\partial u(x,t)}{\partial t} = D \frac{\partial ^2 u(x,t)}{\partial x^2} + Cu(x,t) $$ with the boundary conditions $u(-\frac{L}{2},t)=u(\frac{L}{2},t)=0$ I've ...
1
vote
0answers
82 views

Smallest circumscribed circle in spherical geometry

I work in Python 3 on astrophysics projects. I need to compute the smallest circumscribed circle of a set of points in the sky (so described by Right Ascension and Declination). I have found a code ...
1
vote
1answer
107 views

Double potential well with Python

I'm trying to understand the Schrödinger equation and solving it a bit better, and I'm running into some doubts while coding, even though I am adapting the code to this situation. Also I tried asking ...
3
votes
0answers
103 views

Computing Small Eigenvalues with Sparse Symmetric Indefinite Mass Matrix

I want the eigenvalues of the following generalized eigenvalue problem: $$ Av = \lambda M v $$ where $A\in\mathbb{R}^{n\times n}$ is sparse, symmetric, and positive semi-definite $M\in\mathbb{R}^{n\...
1
vote
0answers
147 views

Use of Morton Key to reduce number of grid points

I asked a question on Stack Overflow Performance Issue with VP Trees and Nearest Neighborsand I was not satisfied with the answer and so I thought I would reword my question for this site and post ...
1
vote
0answers
67 views

Showing date in Paraview's Annotate Time Filter

I have a time dependent data set where each frame corresponds to a certain date. I need to show the time annotation, much like what Annotate Time Filter does, but show the date instead of time as a ...
1
vote
1answer
69 views

Calculate partial trace of an outer product in Python?

I have a python implementation of calculating the partial trace over select dimensions. ...
-1
votes
1answer
44 views

Is it possible to partition 2D data into bins such that each bin contains the same number of samples?

I am trying to sort data following a bivariate distribution into a numpy histogramdd, where each bin should contain the same number of data points (to the nearest whole sample). I expect that some ...
3
votes
1answer
118 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 ...
4
votes
0answers
63 views

Solving a PDE implicitly by iteration in python

Connected to this question here on Computational Science, I've posted a follow-up question on how to solve a PDE using an implicit scheme like Crank-Nicholson in general in this question on SO. But I ...
0
votes
1answer
203 views

How to efficiently solve a QCQP with “dynamic” constraints in Python?

I want to solve a QCQP in Python. It is a problem from finance: maximise return (linear function) given some linear constraints and one quadratic constraint that turns it into a QCQP. Formally, $$\...
1
vote
1answer
68 views

Piecewise-Linear Quadratic Optimization for an “Almost Convex” Problem

I have a 7-14 dimensional piecewise linear cost function I'd like to minimize with two quadratic terms of the form: $$ f(X) = X^tCX + d \sum_i |x_i-x^*_i|^2 + \sum_i P_i(x_i-x^0_i) $$ $$ \sum_i x_i ...
4
votes
1answer
108 views

Solving for a set of coupled ODEs to get correct variable values

My question is about how I can solve a coupled system of ODE's, and print out the variables in a plot. I am solving for an q value and an e value, seen in this set of coupled ODE's below: $$ \begin{...
2
votes
1answer
150 views

Solve 3-D Heat equation with Neumann boundaries

I want to solve the Poisson PDE for heat flow in a 3-D solid cube with given dimensions $x$, $y$, and $z$: $$\rho C\frac{\partial T}{\partial t} = k \Delta T$$ The cube is irradiated with a constant ...
0
votes
1answer
94 views

Python - Fitting a function to data without using Scipy

I'm trying to write a program in python which doesn't need to use extra packages like numpy and scipy. In one part of the project, if I can interpolate a function to a set of data, I can save ...
0
votes
0answers
103 views

Using gmsh python api for meshing a model with grouping elements by their volumes and surfaces

I am trying to use GMSH python api for creating 2d meshes of cad formats. I managed to write a script that can generate mesh successfully. However I need to know how elements are separated across ...
3
votes
2answers
148 views

Integration of the Fermi distribution using Python

I want to calculate the carrier concentration of my semiconductor using this equation: $$ n(x) = \frac{m^*}{\pi\hbar^2}\int_{E_k}^{\infty}\frac{1}{1+\exp\left(\frac{E-E_f}{k_BT}\right)} \mathrm{d}E $$...
3
votes
0answers
73 views

Inconsistency in optimize.minimize

I am trying to fit a time-dependent curve at each time step. I do so in minimizing along $x_c$ the quadratic error between the curve and a reference solution $ 1/(1 + \exp\left(\sqrt{S}(x-x_c)\right) $...
0
votes
0answers
40 views

Poincare map for Arnold-Beltrami-Childress Magnetic Field in Python

I want to plot the Poincare map for Arnold-Beltrami-Childress magnetic field for parameters $A=1, B=0.816, C=0.5773$ in Python for the Poincare section $z=0$. Also, I am not able to understand what ...
3
votes
1answer
54 views

why am I not getting a staircase for the rotation number?

I'm trying to understand the staircase map. Look at this map from the circle to itself: $$ x \stackrel{F}{\mapsto} \big[\omega + x + \tfrac{\epsilon}{2\pi} \sin (2\pi x) \big] \pmod 1 $$ Such a map ...
2
votes
1answer
79 views

Artificial neural networks for Temperature prediction

Imagine I want to consider the temperature for a process given several input varibales. The temperature can be anywhere between 400 and 500 K. Consider I have experimental data to train the network ...
2
votes
1answer
41 views

FFT of “implicitly” uniform data

I am trying to take a Fourier transform of a density field estimated from mock galaxy survey catalogs. Basically, you start with a list of galaxy positions, then you bin these positions over some ...
1
vote
0answers
148 views

Which solvers for BVP in python are the best? Is there something better that scipy.integrate.solve_bvp?

I am trying to solve a boundary value problem with Python. I have been using scipy.integrate.solve_bvp but the result that it is giving me is completely wrong. Basically my code is as follows: ...
3
votes
0answers
82 views

Avoiding divergent solutions with `odeint`? shooting method

I am trying to solve an equation in Python. Basically what I want to do is to solve the equation: $$ \frac{1}{x^2}\frac{d}{dx}\left(Gam \frac{dL}{dx}\right)+L\left(\frac{a^2x^2}{Gam}-m^2\right)=0 $$ ...
0
votes
1answer
131 views

Boole's Rule in python

This is my first post in this forum so please forgive me if it is not the way it should be. My problem is about implementing "Boole's rule" into python. I have succesfully implementet trapezoidal and ...
1
vote
1answer
217 views

Interatomic distance-periodic boundary conditions-non cubic unit cell

I am trying to find interatomic distance considering periodic boundary conditions for hexagon cubic cells (graphite). I tried to follow the answers to these two questions here but am unable to get the ...
1
vote
1answer
74 views

Approximation of a non linear problem with python

I need your help to solve a problem I'm working on for school. My goal is to approximate the coefficients of a weight matrix so that they check particular properties. So I have $W$ the weight matrix ...
6
votes
2answers
297 views

Matrix multiplication accuracy Matlab vs Python

I am translating some Matlab code into Python and I having some problems regarding matrix multiplication accuracy. Assuming we have following data: ...
0
votes
2answers
82 views

reading and processing large GRIB files

I'm trying to convert and process GrADS (grib) files into netcdf files. The files have values every 3 hours (2890 per year), 12 z levels, 120 variables, 241 columns and 236 rows. The data is almost 80 ...
1
vote
1answer
592 views

Why `import numpy as np` for scientific computing? [closed]

Why do scientists bother with the np for numpy? (Note this is more a "philosophical"/reasoning question - let us assume that ...
4
votes
3answers
325 views

Efficient eigen-decomposition of covariance matrix

I am looking for an C/C++/Python algorithm implementation that calculates eigenvalues and eigenvectors of a symmetric, positive semidefinite covariance matrix. A general-purpose eigen-decomposition ...
0
votes
0answers
46 views

Signal Processing with PySpark

I am trying to do some signal processing with PySpark. However, on the API Documentations (link given here), I don't see any libraries for it. The closest is ML and MLLib but they don't contain ...
1
vote
0answers
70 views

computing dual matrix trace norm and tensor gradient in python

I'm trying to write the following function in python: $$ f_\mu(\mathcal X) = f_0(\mathcal X) + \sum_{i = 1}^n \max_{||\mathcal Y_{i(i)}|| \leq1} \alpha_i\langle \mathcal X_{(i)},\mathcal Y_{i(i)} \...
3
votes
2answers
105 views

ODE system with discontinuous right-hand-side

I have a 1st order ODE system. One of the equations is piecewise function of 2 of the dependent variables. I try to solve it in Python environment. \begin{align}\dot x_1 &= x_2 - x_3\\ \dot x_2 &...
0
votes
1answer
133 views

Numerical packages to solve Volterra integral equations

I am looking for numerical packages (ideally Python) to solve second kind Volterra integral equations, such as $$u(t)=g(t)+\int_0^tK(t,s)u(s) ds$$ or Volterra-Fredholm integral equations $$u(x,t)=g(...
2
votes
1answer
336 views

Three dimensional irregular grid data interpolation to regular grid

I have three-dimensional radar reflectivity data obtained as voxels (scans, rays, altitudes). The data has been sampled at irregular spacings and I want to convert this into a regular grid. In ...
0
votes
0answers
118 views

Numerical Sensitivity in Density of States of Tight-binding model

I'm working with the tight-binding model, and I'm trying to learn the basics of how to compute the Density of States (DOS) $N(E)$ numerically. The DOS is given by $$N(E) = \frac{1}{N}\sum_k \delta(...
2
votes
0answers
71 views

2D reaction-diffusion system simulation

I am a complete beginner in numerical simulation and I am pretty lost about how to tackle this problem. I have been trying for some time to find the steady state (or simulate), the following system ...
7
votes
3answers
486 views

Finding the first N roots of transcendental equation

I need to find the first $n$ roots of the transcendental equation \begin{equation} F(k) = J_m'(kr)Y_m'(k)-J'_m(k)Y'_m(kr) \end{equation} for integer values of $m$ and any $r \in [0,1)$ where $J'$ ...
1
vote
2answers
228 views

2D Ising Model, heat capacity decreases with lattice size

The problem I'm trying to make a metropolis simulation of the 2D Ising model. Basically, it's the following, for each monte-carlo step: Visit each lattice site, Compute energy required to flip ...
1
vote
0answers
56 views

Global truncation error behavior at fixed time step

I am trying to solve the following diffusion equation problem: $\frac{\partial f}{\partial t}=\frac{\partial (D\frac{\partial f}{\partial x})}{\partial x}+S$ $D=1+x^{2}+\sin(x)$ $f(x,0)=1 , f(0,t)...
1
vote
3answers
72 views

Discretization Error amplification instead of stagnation to machine precision

I wrote a code on Python 2.7.5 to solve numerically the following differential equation. $\frac{\partial^2f}{\partial x^2}=-S$ $S=\pi^{2}\sin(\pi x)$ S is chosen that way in order to have $f= \sin(\...
1
vote
1answer
130 views

Performing a random walk on a lattice that traps the particles

I am trying to solve this problem where we have a 1D-lattice of size 100 and the particle can start from any position in the lattice and moves randomly on it(with equal probability of moving to either ...
0
votes
1answer
58 views

Wanting an explanation of the variables in Iterative PCA algorithm

I've been trying to implement the CPU GS-PCA algorithm in this paper . The code starts on page 28 I have a program written a script in python which gives the same output as the C++ program in the ...
7
votes
2answers
879 views

Efficiently finding all (x,y,z) points within certain distance of point P

I am using Python, and I have a Pandas dataframe with hundreds of thousands, if not millions, of $(x,y,z)$ coordinates. I am looking to find an efficient method to index the original dataframe so that ...