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

learn more… | top users | synonyms

1
vote
0answers
18 views

Precession of Mercury Python simulation

I was trying to simulate the precession of Mercury based on the perturbed solution: $$\frac{1}{r}=\frac{m}{B^{2}}(1+e\cos\phi+3\frac{m^{2}}{B^{2}}(1+e\phi \sin\phi ...
0
votes
1answer
5 views

Computing the Madelung constant

I am self teaching myself python and computational physics via Mark Newmans book Computational Physics the exercise is 2.9 of Computational Physics I have to compute the Madelung constant. . I have ...
4
votes
0answers
34 views

Large meshing with tetgen

So I have a point cloud that I am creating a 3D flat rectangular surface from. I'm then turning it into a hollow box and connecting the corners by just dropping this surface mesh down. I need it to ...
1
vote
2answers
52 views

How to use the basic Sparse matrix operations (multiplication, .etc) in PyCUDA

I try to use sparse matrix operations in GPU in Python and now try to use PyCUDA with theano. But I can't find how to do sparse matrix and vector multiplication. I only got an example showing how to ...
1
vote
0answers
30 views

scipy.integrate.ode ignores boundary conditions

I am trying to solve the 1-dimensional diffusion problem numerically using method of lines: $$ \frac{\partial c}{\partial t} =D \frac{\partial^2 c}{\partial z^2},$$ where the right hand side is ...
0
votes
1answer
72 views

How do I correctly multiply vectors and matrices in Python and MATLAB?

I have been trying for 2-3 days now to get L2 regularized logistric regression to work in Matlab (CVX) and Python(CVXPY) but no success. I am fairly new to convex optimization so I am quite ...
0
votes
1answer
41 views
1
vote
0answers
48 views

Is this problem statement good for a GPU?

I am used to using GPU hardware for large scale matrix operations and vectorizing mathematical operations on a continuous space which has been discretized for numerical computation, but this is a ...
3
votes
1answer
27 views

divide an array using a changing length sequence of boolean var as index

i have an array of boolean variables. The array has a sort of structure, it's formed of many sequences of zeros and ones, sequences of different length. such as: ...
4
votes
2answers
177 views

Parallelizing a for-loop in Python

Are there any tools in Python that are like Matlab's parfor? I found this thread, but it's four years old. I thought maybe someone here might have more recent experience. Here's an example of the ...
2
votes
1answer
63 views

RK4 giving wrong result [closed]

I am trying to numerically solve a simple second order differential equation $x'' = -x$. I used a new variable $x'=v$, so I have two equations. While it seems simple, it somehow produces a result ...
0
votes
0answers
15 views

How to run a paraview Python code using pvbatch or pv python [migrated]

I am trying to run this Python file using pvpython [filename].py ...
3
votes
1answer
82 views

2D Poisson Solver for Taylor Green Vortex Problem

I am trying to write a 2D Navier Stokes solver using an RK3 for time advancement in python. For debugging, I have converted the RK3 to an Euler step for simplicity. Checking my divergence for my ...
1
vote
1answer
61 views

interactive mode vs animation - python [closed]

Is it better matplotlib interactive mode or matplotlib animation in terms of performance? I have a continous flow of data coming from the serial port. I get 2 measures let's say var1 and var2. I ...
1
vote
2answers
177 views

Python, numpy and complex functions (PDE's)

Update 4 I have almost given up on getting this right. This is the solution to the time-independent Schrodinger's equation, so the analytical solution is: $\psi(x,t) = \psi(x,0)e^{\frac{-iE ...
3
votes
1answer
126 views

Software for triangulating a point set (with restrictions)

I want to triangulate a point-set like the one below. I would like the triangulation of the point-set to have the following properties The triangles must have as vertices the black and orange ...
2
votes
0answers
39 views

Iteratively finding both left and right eigenvectors for non-symmetric complex matrix

I have a complex, non-Hermitian matrix $\mathbf{A}$, for which I need to find a few eigenvalues and eigenvectors in the generalised eigenvalue problem: $$\mathbf{A}\cdot \mathbf{x} = \lambda ...
0
votes
1answer
50 views

Scipy min warning meanings?

What does "Desired error not necessarily achieved due to precision loss" mean in the context of the scipy_fmin methods? I can't ...
1
vote
1answer
231 views

What is the preferred and efficient approach for interpolating multidimensional data?

What is the preferred and efficient approach for interpolating multidimensional data? Things I'm worried about: performance for construction, single/batch evaluation handling dimensions from 1 to 6 ...
0
votes
1answer
65 views

Python plotting a function [closed]

Hi I am new to Python and I am using version 2.7. I came across a problem which requires me to plot a function: $$f(z) =\frac{z^3}{(1-z)^5 ...
1
vote
0answers
20 views

Using HMM for speech synthesis [closed]

I am trying to make a speech synthesizer using a Hidden Markov Model. I read the wikipedia page and several whitepapers and presentations (such as this one) but I am still not sure how this algorithm ...
0
votes
1answer
53 views

Mathematical error when attempting to represent step function using fourier series

I am attempting to work through a very simple problem. Determine the Fourier series expansion for the following heat PDE problem with ICS and BCS: $$ u_{t} = \alpha^2u_{xx}$$ $$ u(0, t) = u(L, t) ...
0
votes
1answer
102 views

Gonzalez algorithm

I'm getting confused about implementing the Gonzalez algorithm for k-center clustering. The algorithm is : let $S$ be a data set Choose $z_1 \in S$ arbitrarily. Number $z$ is center. (In general ...
0
votes
0answers
63 views

Extrapolating a function with increasing slope

I want to extrapolate data for a set of function values on a regular grid. To test different extrapolation routines, I decided sample data from a function, which I believe is the closest known ...
3
votes
2answers
436 views

literature on scientific computing

Maybe, this is a dump question. But anyway. I developed a finite difference code for a class of problems in dynamo theory. I used GNU Octave (MATLAB) which is good for testing. The problem size ...
0
votes
2answers
159 views

How to obtain a convergent solution iteratively for a linear system of equations? [closed]

I am working on a problem that requires an iterative procedure to solve a linear system of equations, the system of equations in matrix form is: $$\underbrace{\begin{bmatrix} r_{11} & r_{12} ...
4
votes
1answer
87 views

How to evaluate a series of derivatives?

Consider the function $$f(\mathbf{x}) = \sum_{n=0}^{N} a_n \left( (\mathbf{b}-\mathbf{x})\cdot \nabla \right)^n \frac{1}{r}$$ where $r = |\mathbf{x}| = \sqrt{(x-x_0)^2 + (y-y_0)^2}$ and $a_n$ and ...
0
votes
0answers
36 views

Phylogenetics in Python 3

I'm looking for a package supported in python 3, which would perform well in visualizing, manipulating and analyzing phylogenetic trees. Since Bio.Phylo isn't very good at this, I looked into ETE2 and ...
0
votes
1answer
92 views

Temperature dependent 1-d conduction in Python?

I'm trying to write a Python code that is a numerical solver for 1-d heat conduction (using FVM) with a temperature dependent thermal conductivity. The solver has three functions I need to iterate ...
2
votes
1answer
110 views

optimization (using python) how to find the most suitable solver?

I have a fitting routine set up. It works, but pretty slow. I was wondering if there is a better method to use. I checked my (forward) code against some literature data and at least I do have no bugs ...
0
votes
1answer
77 views

What Python libraries do I need to do computational physics? [closed]

I need to install Python to do some undergraduate level computational physics (course, not research). What library do I need? Scipy only?
4
votes
2answers
67 views

Computation of multipole expansion of potential not converging

According to Beatson and Greengard's short course on FMM: ( Eq. 5.15 & 5.16 setting k=1, q=1 ) We can approximate a potential $\phi = 1/(r-R)$ using: $$ {1\over |\vec{r}-\vec{R}|} = ...
0
votes
0answers
81 views

Python: Boundary constraint issue with Scipy.optimize

It seems that I have an issue with my boundary conditions when I use the function [fmin_l_bfgs_b][1]. ...
1
vote
0answers
154 views

Stationary 2D/3D Navier-Stokes source code

Trying to solve stationary Navier-Stokes problem for incompressible laminar Newtonian fluid. I've found a couple solutions for instationary Navier-Stokes equations (like FeniCS examples or CFD ...
0
votes
0answers
84 views

Solving 10000, Non-Linear, Simultaneous Equations

Could anyone let me know if there is any optimization solver that I can use to solve about 10,000 simultaneous equations (most of which are non-linear) using Python? Please also advise if it is ...
3
votes
3answers
238 views

Dynamically ending ODE integration in SciPy

I have a light ray moving through space-time, i.e. a curve in R⁴, parametrized by some variable λ. The exact trajectory, i.e. the coordinate functions $x^μ(λ)$ of the curve are given by some ODE ...
1
vote
1answer
180 views

How to write a function-generating code in Python/MATLAB?

I want to write a code that generates a function I(t) that satisfies the following condition: $\frac{\big<I(t)^2\big>}{\big<I(t)\big>^2} > 2$ In other words, $\frac{\lim_{T \to ...
2
votes
0answers
72 views

4th order tensor [closed]

I'm new with FEniCS and Python and I'm stuck with this issue: is there a way to write a 4th order tensor in an easy way to implement? I have to compute the following stiffnes tensor: $A_{ijkl}= ...
5
votes
1answer
280 views

Numerical evaluation of an elliptic integral in python

Goal: I need to evaluate numerically an integral of the following form: $$ \int_0^\infty \frac{dx}{(a^2+x)\sqrt{(a^2+x)(b^2+x)(c^2+x)}} $$ where $a,b,c \in \mathbb{R}$ are in the interval ...
4
votes
0answers
343 views

Why does Matlab's integral outperform integrate.quad in Scipy?

I am experiencing some frustration over the way matlab handles numerical integration vs. Scipy. I observe the following differences in my test code below: Matlab's version runs on average 24 times ...
1
vote
1answer
143 views

Matlab equivalent of scipy's 'vode' and 'zvode' ode routines

In python I have used the ode method from scipy.integrate. There I used the vodeintegrator ...
2
votes
1answer
248 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 ...
11
votes
1answer
906 views

How to avoid catastrophic cancellation in python function?

I am having trouble implementing a function numerically. It suffers from the fact that at large input values the result is a very large number times a very small number. I am not sure if catastrophic ...
2
votes
2answers
323 views

Why does scipy's odeint function give a non-monotonic solution for a problem whose solution should be monotone?

The solution to the ode below looks like it is monotonically increasing: However on closer inspection we see that it is not: How can I ensure that the numerical solution is monotonically ...
1
vote
1answer
86 views

How to deal with indeterminate function limit?

How do I ensure that my function below is well conditioned as $s$ approaches $\infty$? The problem I get is that for large $s$ the function returns an indeterminate form $\frac{0}{0}$. I would ...
0
votes
0answers
115 views

Laplacian of Gaussian (LOG) for Edge Detection

The LOG is determined by the following function as given in this http://homepages.inf.ed.ac.uk/rbf/HIPR2/log.htm. I used Excel and also python to get the LOG kernel. But surprisingly my kernel values ...
0
votes
0answers
622 views

Using scipy.quad to calculate difficult integral

When evaluating the integral below in python using scipy.quad I get the following warning: UserWarning: The maximum number of subdivisions (50) has been achieved. If increasing the limit yields no ...
2
votes
2answers
149 views

How to implement Gauss-Laguerre Quadrature in Python?

To get the hang of Gauss-Laguerre integration I have decided to calculate the following integral numerically, which can be compared to the known analytical solution: \begin{align} \int_0^{\infty} ...
2
votes
1answer
521 views

Is there a Gauss-Laguerre integration routine in Python?

I am reading the book "Numerical Recipes in Fortran 77: The Art of Scientific Computing" (Second Edition) and I came across some methods for numerical integration of 1D functions. More specifically ...
3
votes
2answers
266 views

How to generate a rotated (by 90 degrees) logistic sigmoid function in Python

I created this Python function to generate a sigmoid function where I can modify position and width: ...