Questions tagged [python]

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

442 questions
3k 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: ...
59 views

361 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 ...
923 views

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 \... 0answers 176 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 ... 2answers 1k views Scipy OdeInt solver with Neumann boundary conditions I'm using scipy.odeint to solve Fisher-Kolmogorov equation: $$u_t = u_{xx}+u(1-u)$$ The code can be found here. From Ablowitz and ... 0answers 245 views Return derivative vector from odeint scipy function I have the following function that I want to implement in scipy.integrate.odeint ... 1answer 528 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 ... 1answer 232 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 ... 0answers 502 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 ... 0answers 302 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 ... 1answer 2k 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. $$\frac{\partial u}{\partial t} + \frac{\partial f(u)}{\partial x} =0$$ where: \begin{... 2answers 4k 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, ... 1answer 573 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 ... 1answer 514 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 ... 2answers 5k views Python solvers for mixed-integer nonlinear constrained optimization I want to minimize a black box function f(x), which takes a 8\times3 matrix of non-negative integers as input. Each row specifies a variable, whereas each column specifies a certain time period so ... 1answer 459 views Python trust region optimization code that allows ellipsoid-shaped trust regions Are there any high quality trust region optimization implementations that allow nonspherical ellipsoid trust regions, and are written in Python, or are easy to call from python? By nonspherical ... 0answers 46 views Execute commands when starting ipdb [closed] I usually debug a python script by putting the following line into the source code: import ipdb; ipdb.set_trace() Then when I run the script, ipdb starts. Very ... 0answers 552 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 +e^{2}(\frac{1}{2}-\frac{1}{6}\cos2\...
2k views

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 ...
398 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 ...
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 ...