Stack Exchange Network

Stack Exchange network consists of 175 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.

2
votes
1answer
27 views

Incorporating a potential barrier in a wave-packet simulation (Fourier Transform method)

I'm trying to simulate the scattering of a wave-packet at a potential barrier in Python. I'm using a Fourier Transform method (not sure if its the same as the Split-Step method), where I apply Fourier ...
0
votes
1answer
47 views

Solve multi-dimensional optimization problem using basinhopping

I am searching for an optimization solution, which is a 8d vector representing 4 complex elements, where each element is within the complex circle with maximal radius 1.2. The objective function is: ...
0
votes
1answer
58 views

Python sequence cluster exercise

I am working through an exercise in my textbook and implementing the code in Python to practice dynamic programming. I feel like I am right on the edge of figuring it out, but after many hours, I come ...
-1
votes
0answers
27 views

Charged Particles within magnetic fields [on hold]

I am trying to code the motion of a charged particle within a magnetic field and produce a 3D trajectory plot. The problem I believe is that I need to fix the axes and limit the animation produced. I ...
1
vote
3answers
114 views

Find a solution of large system of inequalities

I have a large system of homogenous inequalities involving 33 real unknowns of the form $$ \vec{F}(z_i)^T \cdot \vec{X}>0\, $$ where $\vec{X} = \left(x_1,...,x_{24}\right)^T$ are the unknowns and ...
0
votes
0answers
11 views

How to choose metrics for evaluating classification results?

Recently we have developed a python library named PyCM specialized for analyzing multi-class confusion matrices. A parameter recommender system has been added in version 1.9 of this module in order ...
0
votes
0answers
27 views

Numerically solving the poisson equation, discretisation of the differential operator, mistake?

I'm attempting to numerically solve the poisson equation using Numpy's LinearOperator class. $$-\nabla \cdot \left(\sigma(x, y)\nabla\right)u(x, y) = 1$$ for $(x, y)\in [0, 1]\times [0, 1]$ with ...
-2
votes
0answers
96 views

Finite Difference Solver Heat Equation

I am trying to write a finite difference solver for the heat equation in Python using FTCS implicit scheme. My details are below; $\frac{\partial{T}}{\partial{t}} = \frac{\partial^2{T}}{\partial{z}^2}...
5
votes
2answers
1k views

Line Integral Convolution (LIC) Requirements

I'm trying to plot some vector fields using LIC technique. More specifically, I'm using the Python solution for this kind of plot. Before applying that approach, I was plotting my vectors as quiver. ...
7
votes
3answers
1k views

How do I reliably generate random numbers in Python distributed across multiple nodes?

Consider the following scenario: I want to perform a large Monte Carlo simulation across a compute cluster with several nodes. To avoid excessive transmission of data, I am going to generate random ...
0
votes
1answer
47 views

Combining multiple coupled 1st order equations in python

I'm having serious troubles with solving translating 3 coupled differential equations into python. The 3 DE's stem from a 4th order DE used to calculate the bending moment of an underwater pipeline ...
-1
votes
0answers
43 views

How to solve coupled equations in python

I'm having serious troubles with translating 3 coupled differential equations into python. The 3 DE's stem from a 4th order DE used to calculate the bending moment of an underwater pipeline that has ...
5
votes
1answer
956 views

What determines the usual chemistry textbook plots of atom orbitals?

In elementary chemistry textbooks you often have pictures like the following one: Are there any conventions how to get them? I am not sure, but I guess that it are contour plots with only one iso-...
-1
votes
0answers
27 views

Rearranging string equation

Hello I have an equation in that is in the form of a string: for example: 2n+5h+19q-6=15j+16a+17a+5 Is there an easy way to move all the variables and coefficients to the left side and the constants ...
1
vote
1answer
33 views

Minimizing the used memory in diffusion simulation using Python

I am recently dealing with a diffusion simulation project and I have come up with the following code: ...
-1
votes
0answers
37 views

Unexpected discontinuous solution for reaction diffusion equation

I've implemented code to find the solution to the discretisation of the following PDE: $$\tau_V \frac{\partial V}{\partial t} = E-V + \lambda^2 \frac{\partial^2 V}{\partial x^2} + i_\text{app}$$ ...
0
votes
1answer
60 views

Unexpected solutions solving an ODE using odeint

I am trying to solve a system of 8 coupled differential equations using scipy's odeint. I have already written my code and it runs fine, but the solutions I get are completely different from what I ...
1
vote
0answers
59 views

SDE solver in python: manual determination of integrator step size (dt)

Aim: I am trying to solve a system of SDEs, while using the SDEint package in python 3.x. It is a system of SDEs adapted from and inspired by the Zombie Apocalypse ...
4
votes
4answers
8k views

LCM builtin in Python / Numpy

I can write a function to find LCM (lowest common multiple) of an array of integers, but I thought it must have been implemented in numpy or scipy and was expecting something like ...
2
votes
1answer
389 views

How to convert MPIAIJ to SEQAIJ matrix in petsc/petsc4py?

I am curious, if there is a function to convert MPIAIJ (distributed matrices in AIJ format) to a SEQAIJ matrix that lie on a single processor. It is possible to do such an operation for PETSc vectors ...
2
votes
1answer
74 views

How to choose a python parallelization library?

I want to preprocess a relatively large dataset using python. I implemented some Dask parallelization and was stunned by the time reduction. I figure there are other libraries or frameworks I could ...
0
votes
1answer
117 views

Heat diffusion - Is this the correct approach to include Newmann boundary conditions?

Thank you for looking at this problem. Is this the correct approach to include neumann boundary conditions? With this solution temperature is not correct, and there´s no diffusion. The model seems ...
1
vote
1answer
225 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(...
3
votes
1answer
128 views

Is this the correct way for solving coupled 1d PDEs using finite difference methods?

I am trying to solve the following coupled PDEs: $$C_e\frac{\partial u(x,t)}{\partial t} = k_{ed}\frac{\partial^2u(x,t)}{\partial^2x} - G_{el}(u(x,t) - v(x,t)) + S(x,t)$$ $$C_l\frac{\partial v(x,t)...
1
vote
0answers
61 views

Speeding up the solution of a large set of nonlinear algebraic equations in `sympy`

I have a quite large algebraic equation system to solve, the system is so large, I can't post the example here, so I am posting it to pastebin. The sympy.solve is ...
0
votes
0answers
56 views

How to compute large condition number of a matrix in Python?

I have a matrix that is extremely singular, but I am still interested in computing the exact condition number, which is the ratio between the largest and smallest singular values. Is it possible to ...
0
votes
0answers
27 views

Determining the pseudo-time period of a system of $n$-pendulums via Kane's method in Python

We can use Kane's method to integrate the equations of motion for a system of $n$ pendulums with arbitrary masses and lengths (see derivation). In particular, if $(x_i,y_i)$ denotes the Cartesian ...
0
votes
1answer
85 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 ...
7
votes
6answers
5k views

Python implementations of Gillespie's direct method

I'm looking for a decent implementation of Gillespie's Direct Method in Python, as if I code the algorithm myself I'm nigh positive I'll do it inefficiently. Anyone have a favorite?
8
votes
2answers
939 views

Minimum path on known potential surface

I'm searching for the minimum path between the minima of a potential surface that is already known on a grid. (source: http://www.math.nus.edu.sg/~matrw/string/) Any point on the path is at an ...
0
votes
1answer
124 views

Python Finite Difference Schemes for 1D Heat Equation: How to express for loop using numpy expression

Hello all, I've recently been introduced to Python and Numpy, and am still a beginner in applying it for numerical methods. I've been performing simple 1D diffusion computations. I suppose my ...
1
vote
1answer
178 views

Efficiently generate a random subgraph (Gs) with maximum degree K, using only edges from an existing graph G

I am looking find a way of efficiently generating a random, undirected subgraph $G_s$ with $N$ vertices, using a subset of edges from an exisiting undirected graph $G$, also of size $N$, where the ...
3
votes
1answer
100 views

Golub-Kahan-Lanczos Bidiagonalization Procedure implementation doesn't produce bidiagonal matrix

I'm trying to implement the aforementioned procedure using this website as a reference. At the end of the page the algorithm is described as follows: I think I've mapped the given algorithm to code ...
2
votes
1answer
47 views

Question about strange outputs from the CVXPY solver

I am familiarizing myself with CVXPY, and encountered a strange problem. I have the following simple toy optimization problem: ...
0
votes
1answer
67 views

How to cope with the following singularity

I have the following integral: $\int_{1}^{Xd} \dfrac{(X^{z_i}-1)}{[X^2 \sum_{l=1}^{N}c_l(X^{z_l}-1)]^{1/2}}dX = \int_{1}^{Xd} h(X) dX$ where: Xd is a real that can be either negative, positive or ...
1
vote
0answers
193 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 ...
0
votes
1answer
156 views

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

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 ...
1
vote
0answers
45 views

Algebraic recursion of Hermite polynomials in SymPy [closed]

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 ...
2
votes
3answers
186 views

Find representatives of vector-space in set of vectors?

Suppose I have a multi-dimensional vector space $X$, and a collection of $n$ vectors $\{x_i\}_{i=1}^n \subset X$, which are not evenly "spaced-out" in $X$. I am searching for $m<<n$ of these $...
0
votes
1answer
18 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 ...
2
votes
0answers
64 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
216 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
100 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
219 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 ...
6
votes
1answer
731 views

FEniCS: how to access coordinates when writing an equation for a trial function

I need to solve the following equation in FEniCS: $$ \boldsymbol{\nabla} \cdot \begin{pmatrix} f(y)\frac{\partial u}{\partial x} - g(x,y)\frac{\partial u}{\partial y} \\ - g(x,y)\frac{\partial u}{\...
2
votes
1answer
157 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 ...
1
vote
1answer
365 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 ...
6
votes
2answers
206 views

Recommended language/environment for large scale semi-continuous biological models

We have a fairly large (maybe 1000 equations) differential-algebraic equation model written in ACSLX, an obsolete modelling environment similar to Modelica. The model represents the evolution of a ...
8
votes
3answers
4k views

fmincg implementation in Python

I'm trying to re-implement Neural Networks in Python. I implemented the cost function and the backpropagation algorithm correctly. I have checked them by executing its Octave equivalent code. But ...
3
votes
0answers
115 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\...