Questions tagged [python]

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

Filter by
Sorted by
Tagged with
0 votes
0 answers
27 views

Complex interpolation for isotopic (precipitation) data

Is there a package that interpolates precipitation data taking into account mountains and oceans? I have so far used Numpy and Basemap but as you can see in the code, the data from Europe affect the ...
user avatar
  • 1
1 vote
0 answers
62 views

How can I reduce the artifact in "Thin Plate Spline" interpolation?

At the Top "right", there is the 2D-density plot of the recorded data (actual), fewer in number. Recorded data has been sampled a on the 8 arms of a regular octagon. These 8 arms are placed ...
user avatar
-1 votes
1 answer
47 views

Fitting gauss-hermite-parametrization to data?

I want to fit this data. I have the following model functions. Classic gaussian: def gauss_model(x, mu, sigma): return np.exp(-0.5*((x-mu)/sigma)**2) And ...
user avatar
-2 votes
0 answers
40 views

Setting up boundary conditions to solve PDEs using method of lines

Objective: To add boundary/initial conditions (BCs/ICs) to a system of ODEs I have used the method of lines to convert a system of PDEs into a system of ODEs. The ODEs themselves involve a lot of ...
user avatar
2 votes
1 answer
97 views

How to ensure the numeric value is always positive in Optimization Python?

I am currently performing optimization onto a quadratic function by manually coding the algorithm: $$\min f = x^T v x - r^T x\\ \text{subject to } x \geq 0\, .$$ Here, optimizing the function without ...
user avatar
1 vote
1 answer
89 views

Huygens Fresnel Diffraction integral using dblquad in python

I am attempting to create a python function to assist in calculating the following numerical integration of the Huygens Fresnel integral in the form of ...
user avatar
0 votes
1 answer
29 views

Get the equilibrium value in coupled ode by python

I am dealing with a coupled ODE. I have already plotted the solutions out using odeint, but I want to get the value of equilibrium. The ode looks like this: ...
user avatar
0 votes
0 answers
67 views

How to solve spatially discretised PDEs (method of lines) in solve_ivp or ODEint?

I can discretise the spatial domain of a system of PDEs using the method of lines, converting the system of PDEs to a system of ODEs (with a time derivative only). These equations (for context they ...
user avatar
1 vote
2 answers
83 views

Simulate Jump-Diffusion $dX_t = \mu(X_t)dt + \sigma(X_t)dW(t) + \int_{\{|c| <1 \}}g(X_t,c)\tilde{N}(dt,dc) + \int_{\{|c| \ge 1 \}}h(X_t,c)N(dt,dc)$

I would like to be able to model an SDE having the form $$dX_t = \mu(X_t)dt + \sigma(X_t)dW(t) + \int_{\{|c| <1 \}}g(X_t,c)\tilde{N}(dt,dc) + \int_{\{|c| \ge 1 \}}h(X_t,c)N(dt,dc).$$ where $W$ is a ...
user avatar
1 vote
0 answers
59 views

Implementation of integration schemes for ordinary differential equations in Python and peformance comparison

I look for a book/manual where I can find implementations of different integration schemes for ordinary differential equations (like 4-th order Runge-Kutta) in Python with Numba. To be more specific, ...
user avatar
0 votes
0 answers
23 views

Compute harmonic (isothermal) coordinates u-v from harmonic function field

I am trying to implement a harmonic map from a surface with a boundary to a unit circle in python. I found this algorithm by Xianfeng Gu, which is almost straight forward: harmonic mapper algorithm ...
user avatar
1 vote
1 answer
48 views

Easy way to perform solver over pandas dataframe

I'm moving from Excel to Python and I'm trying to solve these equations: $$\begin{align} X_1&=\bigg[\big(3.47-\log(X_2)\big)^2+\big(\log(c)+1.22)^2\bigg]^{0.5}\\ X_2&=\frac{a}{101.32}\bigg(\...
user avatar
1 vote
0 answers
111 views

CFD in Python: Mesh Generation

I am trying to set up a 3D CFD scheme for thermal and flow modelling in Python using the finite volume method. The first concern is to build the geometry and an accompanying mesh that is efficient for ...
user avatar
2 votes
1 answer
107 views

2nd order differential equation coupled to integro-differential equation in python

I'm trying to solve the following equations numerically in python $$\begin{align} 12\pi\int_0^\infty drf(r)\phi(r)r^4&=E\\ f(r)-\frac{1}{2\mu}\bigg(\frac{d^2\phi(r)}{dr^2}+\frac{2}{r}\frac{d\phi(r)...
user avatar
1 vote
0 answers
56 views

Open boundary condition for 1d wave equation with variable wave speed using finite differences

I have implemented a finite difference solver for the 1d wave equation with variable wave speed: $$ u_{tt} = c(x)u_{xx}, \hspace{10mm}c(x) = \dfrac{6 -x^2}{2} \hspace{5mm} $$ on $-2 \leq x \leq 2, t &...
user avatar
2 votes
1 answer
94 views

Boundary value problem with singularity and boundary condition at infinity

I'm trying to solve the following boundary value problem on $[0,\infty]$: $$f^{\prime \prime}=-\frac{1}{r} f^{\prime}+\frac{1}{r^{2}} f+m^{2} f+2 \lambda f^{3}$$ $$f(0)=0 \ ; f(\infty)=\sqrt{-m^2/(2\...
user avatar
2 votes
0 answers
70 views

Numerical instability in the inverse Laplace transform

I have a problem with Laplace inversion and my function is not numerically stable for the Laplace inverse, but I do not understand the cause of this problem. Here is my code and graph of this problem. ...
user avatar
0 votes
0 answers
41 views

Examples of kinetic modeling with optimization techniques in Python

We are looking for studies or tools that implemented kinetic modeling with parameter estimation differential evolution or similar optimization techniques in Python. We are trying to understand what ...
user avatar
0 votes
0 answers
25 views

How can I couple MCNP with FLUKA? To attain reactor dynamics and simulate an ADS experiment? (Under Subcritical fast system)

I'm new in Particle Physics based Computing. I want to simulate an ADS experiment (Accelerator Driven System) in subcritical fast system. I was advised to simulate the experiment with FLUKA with MCNP ...
user avatar
0 votes
1 answer
78 views

How to deal with solving coupled ODE systems where variables are updated multiple times within each timestep?

I'm solving a system of coupled ODEs using Euler integration for simplicity. To make this concrete, please see the (extremely simplified) minimal working example below in Python. Imagine we have a box ...
user avatar
0 votes
0 answers
51 views

Help Finding Roots

I need to refine a level curve representing an implicit function that is not numerically solvable in sympy. The initial solution set generated by matplotlib's ...
user avatar
  • 143
4 votes
1 answer
107 views

Rotate a 2D contour plot through 360 degrees to create 3D plot (Python, Mayavi/Matplotlib)

I have three 1D arrays, which represent radius, height, and an intensity measured at that point. I have plotted these to create a 2D contour map. A simple example of the way in which the data is ...
user avatar
  • 41
1 vote
0 answers
63 views

Help with CVXPY and Disciplined Convex Programming

I'm trying to recreate Figure 1 in this paper. This requires maximizing equation (19), which I have convinced myself is concave, but I am having trouble implementing it in CVXPY. Here is the code I ...
user avatar
0 votes
0 answers
39 views

Oscillating eigenvectors for 2d-laplace operator

I am trying to calculate the eigenvectors of a Laplace-operator in 2d, with boundary conditions equal to $u=0$ if $x, y$ are outside of a rectangle defined as $(0.5, 0.5), (1.5, 1.5)$. For that I used ...
user avatar
  • 533
2 votes
0 answers
68 views

solve Ax=b for outrigger A matrix python

I implement Crank-Nicolson 2D finite-difference method. I get a matrix A which is banded with 1 band above and below the main diagonal, but also contains 2 additional bands , further apart from the ...
user avatar
  • 131
1 vote
1 answer
76 views

Beam propogation method for a waveguide. How to get single mode?

I am simulating a waveguide using diffractio python library (https://diffractio.readthedocs.io/en/latest/readme.html). The idea is to create a single mode waveguide using wave propogation method. ...
user avatar
3 votes
1 answer
122 views

Questions regarding the result of the CVXPY

I want to optimize the function $$\min_{X \in \mathbb{S}^{n}_{+}} \mbox{tr} \left( C^T X \right) + \mbox{tr} \left( X^{-1} \right),$$ of which I optimize the equivalent problem $$\min \mbox{tr}\left(C^...
user avatar
  • 133
2 votes
1 answer
98 views

Can't solve second order differential equation with scipy

Most of my knowledge about numerically solving differential equations is long forgotten. Unfortunately I stumbled upon a physics problem where I need to do exactly that. I'm trying to describe the ...
user avatar
  • 31
5 votes
1 answer
118 views

Python: Underflow vs. exp of large negative numbers

Suppose I have values of log(P(x_i)), i.e. log-probabilities to events x_i. The probabilities are very small, so that these log-values are of the order of -1e3. I want to compute an expectation value. ...
user avatar
0 votes
0 answers
36 views

Kaplan-Glass Determinism Test - Python

I have projected a 2-dimensional phase space onto a graph and attempted to coarse grain the embedding. I'm attempting to perform the Kaplan-Glass Determinism Test. Link: http://www.medicine.mcgill.ca/...
user avatar
2 votes
0 answers
56 views

Cyipopt fails to converge for NLP problem which fmincon() can solve

I'm currently trying to implement a python script for solving a constrained nonlinear optimization problem with ~800 variables and 2 constraints, one linear and one nonlinear. There already exists a ...
user avatar
7 votes
0 answers
98 views

Can we sparse solve a few eigenvalues specified by index range?

I need to solve a few eigenvalues of a large sparse matrix specified by their index range. These indices are according to the whole eigenspectrum sorted in algebraic (not absolute value) ascending ...
user avatar
2 votes
1 answer
450 views

How to solve the following SDP with Python?

Supposing that $\{B_{ij}\}_{i,j}$ are all Hermitian matrices and $\{c_{ijk}\}_{i,j,k}$ are all real numbers, the corresponding SDP(Semidefinite Programming) problem is as follows: $$ \begin{aligned} &...
user avatar
0 votes
0 answers
81 views

Weighted Jacobi Not Working on 1D Poisson (Issue with Optimal $\omega$)

I've been trying to learn some numerical linear algebra, and I decided to try to implement the weighted Jacobi method to the 1D Poisson problem $$-u''(x)=f(x),\qquad u(0)=a,\ u(1)=b,$$ where we ...
user avatar
1 vote
1 answer
41 views

Why does this implementation for Eisenstein integer pairs of Euclid's method for finding greatest common denominators get stuck for this one point?

My Math SE question determining if a coincident point in a pair of rotated hexagonal lattices is closest to the origin? explains the problem I have. I won't reproduce the whole thing in detail here, ...
user avatar
  • 842
4 votes
1 answer
192 views

Stochastic SIR using SDEint python package

I want to use the SDEint package to give a numerical solution (plot) of the following stochastic SIR model. Namely, a system of SDEs. $$\begin{cases} dS = -\beta SIdt - \sigma SIdW \\ dI = (\beta SI -...
user avatar
0 votes
0 answers
21 views

How to determine the minimum grid length | Numerical Plasma physics

I am trying to understand the attached python 3X code. The following dispersion relation is given $$\epsilon (k, \omega) = 1 - \frac 1 2 \left[ \frac{\omega_p^2}{(\omega-kv_0)^2} + \frac{\omega_p^2}{(\...
user avatar
  • 101
0 votes
0 answers
24 views

Need help in attempting to solve an MHD eigenvalue problem

Background I am attempting to numerically solve the ideal MHD equations in normal mode form for a Harris current sheet. The linearized perturbed MHD equations can be written in a normal mode form: $$ -...
user avatar
  • 101
1 vote
0 answers
100 views

How to constrain the every optimized vector component to be nonnegative?

I am building a gradient descent model based on portfolio optimization. Currently, I have finished the model and am able to run it smoothly without any problem. However, there's one issue that I ...
user avatar
1 vote
1 answer
181 views

Schrodinger's Equation differential

I am working on a modified version of Schrodinger's equation (time-independent) where $\frac{d^2ψ}{dx^2}=-2(E-V)ψ$, where I have to consider $V = 0$ at all times. I have been asked to use Python in ...
user avatar
5 votes
1 answer
89 views

Are Python/MATLAB/Mathematica numerical eigenvectors affected by eigenvalue degeneracies outside region of calculation?

I have a discretized 2D mesh over which I calculate eigenvalues and eigenvectors of some Hermitian 2 x 2 matrix at each point along a closed loop parameterized by parameter t. The eigenvectors are ...
user avatar
2 votes
0 answers
58 views

Efficient way of calculating a cumulative integral with prefactor

I have a grid of points $x_i$ and corresponding function values $y_i=f(x_i)$. I'm interesting in something like the cumulant of $f$, but it has an awkward prefactor. The desired quantity we'll call $$...
user avatar
4 votes
0 answers
116 views

How amenable is this 2D Frenkel–Kontorova-like energy minimization problem in Python to the use of a modest PC + GPU? (Heavy reliance on indexing)

@Richard's answer to Going to try to move some of my scipy/numpy calculation to a new GPU, how to avoid disappointing results? is quite helpful, and as promised I've added a simple running example ...
user avatar
  • 842
3 votes
1 answer
111 views

Question about energy in the shallow water equations on a staggered grid

I think this is a question about the energy conservation of a numerical integrator. I'm studying the linearized 1D shallow water equations in python - for reference, here they are: $$ \frac{\partial u}...
user avatar
0 votes
0 answers
58 views

Overflow in Solving numerically the 1D Kuramoto-Sivashinsky Equation using spectral methods

I'm having trouble with the following implementation of the KS model (see below) found on Solving numerically the 1D Kuramoto-Sivashinsky Equation using spectral methods When tN > 300 an overflow ...
user avatar
  • 1
1 vote
0 answers
163 views

How to write a simple finite element solver in python in order to solve Poisson equation in 2D

I would like to write a simple finite element solver in python in order to solve 2D Poisson equation and then visualize it. $$ -\nabla^{2} u(x,y)=f(x,y), \quad x,y \quad in \quad \Omega\\ u(x,y) = u_D ...
user avatar
  • 418
3 votes
1 answer
193 views

Going to try to move some of my scipy/numpy calculation to a new GPU, how to avoid disappointing results?

update: I've refactored the question based on helpful advice in the linked meta. I'm a heavy user of Python's NumPy and SciPy (and not much else) and for years I could run anything I need on my laptop....
user avatar
  • 842
4 votes
0 answers
50 views

How to troubleshoot numerical instability using finite difference for steady-state non-linear heat conduction equation

I have a problem which I believe is numerical instability when trying to solve a heat conduction equation using finite difference. The short version is that when the parameter $I=80.3$ I get the blue ...
user avatar
4 votes
1 answer
214 views

Is there any way/any python function to calculate the condition number of the roots of a polynomial directly?

I know that NumPy has linalg.cond(A) to find the condition number of a matrix A. But, if I want to find the condition numbers of the roots of a large polynomial ...
user avatar
1 vote
1 answer
86 views

solve_ivp doesn't work with toms748

I have the following code ...
user avatar
  • 123

1
2 3 4 5
16