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.

7
votes
3answers
494 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
260 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
77 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
140 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
59 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
974 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 ...
1
vote
1answer
388 views

Applying Neumann boundaries to Crank-Nicolson solution in python

Consider the heat equation $$u_t = \kappa u_{xx}$$ with boundary conditions of $$u(x,0)=0\\ u(0,t)=100\\ u(l,t)=0$$ Numerical analysis by pyton can be done with ...
3
votes
0answers
149 views

Open source implementation of Multiscale Combinatorial Grouping

I would like to use Multiscale Combinatorial Grouping for my PhD research. However, I am restricted to use open-source implementations and this one runs on Matlab. Does anyone know of an equivalent ...
0
votes
1answer
352 views

How to define the derivative for Scipy.Optimize.Minimize

I am trying to use scipy.optimize.minimize to minimise a quadratic objective function: $f(x) =x^\top Q x$. As a start, I have successfully implemented this using the built-in Nelder-Mead Simplex ...
0
votes
1answer
79 views

Why does multithreaded code Segfault in 64-bit but not 32-bit [closed]

I have written some multithreaded code using PyOpenCL, which works fine under the following conditions: GPU 32-bit floating point values (Intel Iris GPU can only handle single precision values) CPU ...
2
votes
1answer
512 views

Solving a system of quadratic equations in Python

I'd like to solve numerically a system of quadratic equations: $A_{11}x_1+A_{12}x_2+A_{13}x_3+B_{12}x_1x_2+B_{13}x_1x_3=C_1$ $A_{21}x_1+A_{22}x_2+A_{23}x_3+B_{21}x_2x_1+B_{23}x_2x_3=C_2$ $A_{31}x_1+...
1
vote
0answers
160 views

Optimization of a blackbox function with an equality constraint?

I believe this would be an interesting problem. I have a blackbox function which can take 2-60 input variables $(X_1,X_2,...X_n)$ which are to be optimized. I'm calling this objective function as a ...
0
votes
1answer
1k views

Solving a cubic equation in Python using fsolve - only one root is obtained

I am trying to solve a cubic equation in Python. However I am getting only one root of the equation. Please find the code snippet below. ...
1
vote
0answers
68 views

Rank filter on an nXm array using python

I would like to apply a rank filter on an nXm numpy array. Let's say I have this array: ...
0
votes
1answer
65 views

Anyone who knows fine neural network code or module for python?

I want to change my main platform from Matlab to Python due to my work, and I mainly used Matlab for the neural network, so I want to do the same thing in the Python either. I used to make my own ...
6
votes
2answers
191 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 ...
1
vote
1answer
323 views

Iterative camera calibration - No convergence

I am trying to implement the algorithm from the research paper "Accurate Camera Calibration using Iterative Refinement of Control Points" from Datta et al. Running many iterations does not show a ...
0
votes
1answer
118 views

Finite difference method for the electric field of the electron gun

Can anybody help me to find books or MATLAB code examples for solving electric field of the electron gun(fig.1)with finite difference method? Python code examples are also perfect. The electron gun ...
2
votes
2answers
66 views

Find combinations of variables with variable bounds to get summed up to a required value (using Python)

Let's say I have n variables. Each variable has lower and upper bounds. I want to find all suitable combinations of these variables to sum up to a required value. An example with two variables: $$ ...
1
vote
0answers
606 views

Software for easy spherical coordinate plotting from data file

Does anyone have any suggestions for good open source plotting software which has good graphical spherical coordinate plotting (from a data file). I have a three column data file where column 1 is $\...
0
votes
1answer
537 views

Numpy.polyfit with regularization

I am trying to use the numpy polyfit method to add regularization to my solution. My non-regularized solution is ...
1
vote
2answers
404 views

Continuum removal algorithm in python

I'm using python 2.7 (on jupyter notebook, win10 64 bit) to perform my analysis. I need to perform continuum removal (CR) on a reflectance spectrum data. I need it to be as described here. EDITED: ...
1
vote
0answers
101 views

Finding integer/lattice points (coordinates) inside a polytope/polyhedra?

I am using Python but I wouldn't mind changing language. All I have gotten from my research are tools to count the number of (lattice) points inside a region given the equations for the planes that ...
3
votes
1answer
246 views

Computing the Ising Model for NiO

I am trying to compute the Ising model for NiO. As O carries no magnetic moment, I only need to consider the case of Ni which requires a second nearest neighbour Ising model. As can be seen in the ...
3
votes
1answer
258 views

Comparing Algorithmic complexity, ODE Solvers (Big O)

I am currently using the following three methods to solve differential equations: 4th order Runge Kutta Method Euler Method Internal scipy methods: ...
0
votes
1answer
32 views

Inverting a transition matrix with small grid size

Time is continuous time. I have a 3D state space, and transition rates across all of these. Using the transition rates, I can compute a generator matrix A ...
0
votes
1answer
279 views

Numpy attributes not recognized in Numba [closed]

Numba offers JIT for Python. In its documentation it says "One objective of Numba is having a seamless integration with NumPy." So why including some of the simplest features from numpy isn't ...
1
vote
1answer
249 views

Trajectory optimization for smoothness

I want to achieve the following in 2D (and without obstacles): Given start position A and end position B, generate the path between the two points that optimizes a cost function that depends on total ...
1
vote
0answers
148 views

Vectorised root finding in Python

I have an array of size (254, 80) which I am trying to use Scipy's fsolve on. I have found that the speed of using fsolve on a vector is quicker than it is in a for loop but only for vectors upto ...
1
vote
0answers
85 views

FiPy with derivative source terms

I have a coupled nonlinear PDE system in 1 spatial dimension, in which I want to solve using FiPy. The dependent variables are $n$ and $T$: \begin{align} \frac{\partial n}{\partial t} \,&=\, D\,\...
1
vote
0answers
40 views

Python package to calculate static force and moments of rigid body

Which Python package is suited for solving problems of the following type? Given the rigid body depicted in violet in the following sketch I would like to do the following: Define cartesian ...
1
vote
0answers
53 views

How to fast estimate derivates for calculating quantiles

I would like to know if there exists a package or how one can fast calculate the quantiles of a function within python, where the inverse of the function for calculating the quantile depends on the ...
2
votes
1answer
3k views

2D Ising Model in Python

I am trying to calculate the energy, magnetization and specific heat of a two dimensional lattice using the metropolis monte carlo algorithm. ...
1
vote
0answers
83 views

Fourier transform spherical system

I need to take the Fourier transform of a 3D function $h(r)=h(|r|)$ so that I can invert a convolution problem. What is the best way to do this with Python? I know the the FT is equivalent to a sine ...
1
vote
0answers
90 views

Hello word in FEniCS? [closed]

I am trying to start using FEniCS, but have a problem with the simple hello world examples given in the books. Could you please give me the simplest hello world ...
3
votes
2answers
222 views

Writing a programming code directly from the mathematical formula?

For using any programming language, a mathematical formula should be written in the corresponding code. I wonder if there is any service (for any programming language, Matlab, Mathematica, Python, etc)...
3
votes
0answers
84 views

How to optimize for decay constant in exponential-like function?

I've got a data set of points $M_O .. M_N$ for time points $t_0 .. t_N$, where $N$ is approximately 10-20, and the spacing of time is not uniform (i.e., $t_{i+1}-t_i$ is not constant for all i). It is ...
1
vote
0answers
160 views

Solution to 1D consolidation problem python implementation

A solution to the 1D consolidation problem is given by $$\frac{\partial}{\partial t} p = c_{v} \frac{\partial^{2}}{\partial y^{2}} p$$ where $p$ is the pore water pressure, $c_v$ is the ...
1
vote
0answers
67 views

How to measure euclidean distance between points with vtkDelaunay3D package? [closed]

I'm working with python vtkDelaunay3D package for a special purpose. I have set some points but I do not know how can I measure euclidean distance between points with this package. Is there anyone who ...
3
votes
0answers
80 views

Precision not improving by decreasing step-size in nonlinear Schrödinger

I tried to simulate soliton propagation by solving the nonlinear Schrödinger equation using the split-step Fourier method. The following is an example of the Matlab code copied from a textbook. ...
0
votes
1answer
194 views

``scipy.odeint`` giving different answer than analytical

I was using scipy.integrate.odeint function , the ode is $$\frac{y\ dx - x\ dy}{(x+y)^2} + dy = dx$$ with solution $$y^2 - x^2 - y = c (x + y)\ .$$ Solving it ...
3
votes
1answer
885 views

Loop optimization with f2py, Cython and Numba

I tried to used f2py, Cython and Numba to make a simple loop structure be faster in python. Python implementation: ...
4
votes
1answer
301 views

Poor SVD reconstruction of singular matrix

I am trying to calculate the singular value decomposition of this matrix using numpy.linalg.svd . However, reconstructing the matrix from the SVD gives a poor ...
1
vote
1answer
2k views

How to simulate 3D diffusion in python?

I want to simulate a simple 3D diffusion (e.g., an ink released from one side of a vessel) using SciPy. There are some tutorials for one-dimensional diffusion. ...
1
vote
0answers
46 views

Update model parameter with new data, discarding old data

I have this dataset, and I am using y = (a * x^n) / (b + x^n) Hill function as the model, where a is the limit of the Hill curve,...
1
vote
1answer
703 views

Solve a set of multivariate linear inequalities with constraints in Python

I'm trying to implement Dinur-Nissim algorithm and am stuck at how to solve the set of linear inequalities with multiple unknowns and a large number of equations along with constraints. Example: \...
2
votes
3answers
182 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 $...
1
vote
0answers
235 views

Optimizing an error function involving rotation vectors in Python

I'm prototyping a system that finds the 3D pose of a object in a video sequence. For this I minimize a error function involving the rotation and translation of the object as parameters and two sets of ...
2
votes
2answers
281 views

Runge Kutta (RK4) to solve coupled harmonic oscillators [duplicate]

I have the same problem as in this question. But can someone elaborate on the answer? The poster says that: Solving this system of 4 ODE's with rk4 will solve for all your state variables ...