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

learn more… | top users | synonyms

3
votes
0answers
46 views

scipy.linalg.sparse.eigsh does not work for generalised eigenvalues

I asked this question over at StackOverflow and someone told me that I'd get a better answer here. So here's my problem: I'm working on a machine learning project which involves doing a Principal ...
4
votes
2answers
149 views

Plot integral function with scipy and matplotlib

I want to plot a numerical integral function of some function $f$ using scipy and matplotlib. How can I do this? I tried the ...
1
vote
2answers
129 views

Programming language for HPC [closed]

I'm planning on building a program that will carry out HPC. I'm aware that C/C++ is significantly better than Python in terms of the speed of computation. However, I'm not yet proficient in C/C++, so ...
2
votes
1answer
63 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: ...
0
votes
0answers
44 views

Solving a nonlinear problem with CDF

I'm trying to solve this problem: $\begin{cases} \partial_t E=-k\left([f(\rho)-i.\left[\delta+\frac{1}{2}a\left[\dfrac{\nabla^2_{\bot}}{4}+1-\rho^2\right]\right]]E - 2CP\right)\\ \partial_t ...
5
votes
2answers
93 views

How to read the number of periods of this complicated graph?

I have two data sets that are quasi-periodic. They have the same period and can be seen clearly by eye. For example when $x\in(100,200)$, both of them have about 32 periods. Below is a zoom-in of ...
1
vote
1answer
35 views

How to use compiled python packages for matrix initialization

Assume I have an expression for an matrix initialization, for example the following: A[i,i-2*j+k] = B[i-k] * C[i] * D[i+j+k] In order to execute such a process, I could loop over all i, j and k. ...
0
votes
1answer
120 views

Finite-difference approximation of the 2nd derivative operator matrix for a staggered grid

I'm working on a computational physics assignment and I was looking for some help as I've got stuck! The question is: Write a function to create the finite-difference approximation of the 2nd ...
1
vote
0answers
99 views

Is it worth switching to timesteppers provided by PETSc if I can't write down a Jacobian for my problem? Case study with “the amoeba” toy problem

I am considering using petsc4py instead of scipy.integrate.odeint (which is a wrapper for Fortran solvers) for a problem ...
0
votes
2answers
163 views

Multiple Coupled Differential Equation solution in Python

I have 4 ordinary differential equations that are coupled. The variables in the 4 equations are functions of time and space and one of them is second order in space. \begin{equation} \frac{ \partial ...
0
votes
1answer
107 views

Heat Equation - PDE

I'm trying to model the Black-Scholes Equation (transformed into a heat equation) using method of lines in Python. The transformed formula is basically \begin{equation*} \frac{\partial u}{\partial ...
0
votes
0answers
72 views

Inverse quadratic method only makes one iteration - python

I'm tryin' to implement this method with python3 but i don't solve the problem. This is my code: ...
3
votes
2answers
72 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 ...
0
votes
2answers
115 views

Wave Equation PDE [closed]

I'm trying to solve the following PDE wave equation using method of lines: Wave Equation: u_tt = u_xx with initial condition: u(0,x) = sin*pi,u_t(0,x)=0, 0 < x < 1 boundary ...
3
votes
2answers
177 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$ ...
1
vote
0answers
48 views

Need suggestions on how to implement this time stepping for wave equation

I have the following system of equations obtained by implementing Sympletic Euler time scheme to wave equation. I want to model this in Fenics. Here 'u' is the displacement and 'p' is corresponding ...
1
vote
3answers
123 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 ...
0
votes
0answers
42 views

How to model softening of concrete?

I have a question about acquiring the softening part of the compressive stress-stain curve of concrete under uniaxial static loading. I have tried very different options: Concrete Damaged Plasticity ...
0
votes
0answers
49 views

How to Optimisation to return decimal and integer values-Python?

I want to optimize a function, where the optimization algorithm should return parameters of two types, decimal and integer. Is this possible? I am using python.
0
votes
0answers
44 views

Variational Monte Carlo: Variational energy is lower than ground state energy

I'm writing a VMC simulation for hydrogen and helium atoms, but in both my codes my variational energy for certain wavefunctions is not only statistically different from my expectation value, but it ...
1
vote
1answer
37 views

Calculate proportions of exponentially weighted factors avoiding underflow problem

I am trying to implement in Python this ratio: $\frac{w_t(i)}{\sum w_t(j)}$ where $w_t(i) = w_{t-1}(i)\cdot\exp{(-x_{t}(i))}$, i.e. the weights are exponentially decreasing without running into ...
2
votes
0answers
82 views

Solving constrained BVP, singular Jacobian

The boundary value problem is $$ \begin{cases} \dot{x}_i = \begin{cases} (0.5D^{-1}\psi)_i, \text{ if }(0.5D^{-1}\psi)_i \le 0 \\ 0 \text{, otherwise} \end{cases} \\ \dot{\psi} = 2\Sigma x \\ x(0) ...
4
votes
1answer
190 views

Numerical solution of Geodesic differential equations with Python

I have made a solver based on the SymPy.diffgeom library, where I use Scipy.Integrate to solve the following system of second order differential equations : \begin{align} u'' &+ ...
1
vote
2answers
63 views

Heat Equation Solution in One Dimension (x, t)

We're currently solving the heat equation as a part of the PDE sequence in class. We've been given the formula:$$T(i, n+1) = T(i,n)+\alpha \left [\frac{T(i+1,n)-2 T(i, n)+T(i-1,n)}{\Delta x^2} \right ...
1
vote
0answers
66 views

best package choice for visualizing agent based model simulations in python

This is a visualization/programming design problem. I am working on building a geospatial agent based model, meaning that there are multiple agents interacting within some particular spatial ...
2
votes
3answers
189 views

Runge-Kutta Simulation For Projectile Motion With Drag

I am attempting to simulate projectile flight with drag. However, with a timestep of 0.1 seconds, I am consistently getting an error of ~0.1-1%. ...
1
vote
1answer
77 views

Diffusion with space dependent drift in Fipy

I need to solve a diffusion equation in periodic boundary conditions using fipy but I would like to have a drift term that depends on the position so like this: $$ \partial_t u(x,t) = \partial_x^2 ...
0
votes
1answer
40 views

Solve a pair of coupled nonlinear equations within certain limits

This answer to this question works only for situations in which the desired solution to the coupled functions is not restricted to a certain range. But what if, for example, we wanted a solution such ...
0
votes
0answers
22 views

fortran lib for sine weave with vectors as input

Hi i have problem with calculating sine wave. With python numpy, numexpr calculation of sine wave from equation z = sum(Asin(omt+eps),axis=1), takes me something like 1min50sec when shapes of A,om,eps ...
1
vote
1answer
55 views

Python package for large absolute value optimisation

I have an absolute value optimisation problem $$\min_x \sum |r-Cx|$$ where $x$ is small around 200 dimension. But $C$ has lots of rows, $C_{30000\times200}$ and $r$ is $30000\times1$. So this will ...
2
votes
0answers
93 views

Adaptive Finite Element Method - Laplace

I'm currently attempting to turn my code for solving the laplace equation using finite element approximations into an adaptive one using the dual weighted residual as my error estimator: i.e. my ...
0
votes
0answers
51 views

Laplace Operator with PyNFFT

I am learning to use PyNFFT for nonuniform FFT. I try to apply the laplace operator to functions. As a test, I want to take $f(x) = \cos( 2\pi i k \cdot x)$, calcualte (using the package) $\Delta f$ ...
6
votes
1answer
136 views

Test of 3rd-order vs 4th-order symplectic integrator with strange result

In my answer to a question on MSE regarding a 2D Hamiltonian physics simulation, I have suggested using a higher-order symplectic integrator. Then I thought it might be a good idea to demonstrate the ...
1
vote
1answer
87 views

Computation of plane wave scattering on semi infinite plane

I have attempted to code up the simple math required to plot the total field set up by an incident plane wave on a semi-infinite flat plate which can be found here. To summarise: $$\phi_s(r,\theta ) ...
1
vote
0answers
65 views

How to adjust scikit-learn FactorAnalysis() settings to get scores output similar to one from factanal() in R?

I'm new to factor analysis and I need to compute factor scores using Python. I have R code to compute scores and I want to ...
3
votes
1answer
262 views

Alternatives to numpy.einsum

Given an $n_1 \times \cdots \times n_k \times g \times g$ tensor $A$ (i.e. a collection of $g \times g$ matrices) and an $n_1 \times \cdots \times n_k \times g$ tensor $b$ (i.e. a collection of ...
1
vote
0answers
73 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
176 views

How can I solve wave equation for circular membrane in polar coordinates?

The original equation is $$\frac{1}{c^2} \frac{\partial^2 u}{\partial t^2} = \frac{\partial^2 u}{\partial r^2} + \frac{1}{r}\frac{\partial u}{\partial r} + \frac{1}{r^2}\frac{\partial^2 u}{\partial ...
1
vote
0answers
124 views

Differences in answers between Python and Fortran [closed]

I am translating a piece of Fortran code into Python and am testing my code with a certain test case. All the results differ with 0.04% compared to the Fortran results. This is a very small ...
2
votes
2answers
138 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 ...
2
votes
0answers
52 views

Return derivative vector from odeint scipy function

I have the following function that I want to implement in scipy.integrate.odeint ...
3
votes
1answer
149 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 ...
5
votes
1answer
136 views

Iterative Cunnigham correction in Millikans oil-drop experiment

I tried to write an analysis program in python for the Millikan experiment based on a paper from Jones "The Millikan oil‐drop experiment: Making it worthwhile" However, I cannot reproduce the ...
1
vote
0answers
88 views

Solving a system of 4 coupled PDEs representing variable diffusivity

I have four partial differential equations representing mass conservation of two compressible fluid phases (marked by subscripts $p1$ and $p2$) in two different continuum media (marked by subscripts ...
1
vote
0answers
92 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 ...
1
vote
1answer
272 views

Implementation of 1D Advection in Python using WENO and ENO schemes [closed]

I'm trying to implement 1D advection solver using WENO and ENO schemes. \begin{equation} \frac{\partial u}{\partial t} + \frac{\partial f(u)}{\partial x} =0 \end{equation} where: ...
2
votes
2answers
489 views

Solve non-linear set of three equations using scipy

I need to solve a non-linear set of three equations using scipy. However, I do not have any clue on which algorithm is suitable for my problem from a mathematical point of view (stability, ...
1
vote
1answer
102 views

Convert Image of Map to 2D Grid in Python

I have this map showing the geography of Europe (below), and I wish to convert it to a matrix in python that would be a 2D approximation of this image where 0's would represent the ocean and 1's would ...
0
votes
0answers
68 views

Cyclic Coordinate Descent Optimization for Bayes Logistic Regression (Code Problem?)

I am trying to reproduce the CLG algorithm for the Laplace prior given in Genkin et al to find the MAP estimates for a logistic regression model. I am using Python (Anaconda 2.2) with Numpy to ...
1
vote
1answer
94 views

Improper Numerical integral

I am self teaching myself python and computational physics via Mark Newmans book Computational Physics the exercise is 5.17 of Computational Physics. I have to shift the limits of integration for an ...