Skip to main content

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
20 views

Pytho Gekko error "Inequality Definition invalid inequalities: z > x < y"

I'm trying to solve an optimization problem in microeconomics with the Gekko library. In the problem, the objective is to maximize utility (u) subject to the limitation of an income R equal to 100. ...
Helson's user avatar
  • 1
2 votes
0 answers
103 views

Coding a performant flexible scientific code with Python

I aim to code a PDE flexible fast PDE solver. I read and noticed multiple approaches: Python + Numba Python + Cython Python + some compiled language (c++/fortran) The equations to be solved are ...
mle's user avatar
  • 147
0 votes
0 answers
32 views

Help needed in generating a list of radii

I am trying to generate a list of radii between two given points (0 and 1 in this example). Below is my code in Python to generate the list. ...
Sumit Banerjee's user avatar
0 votes
0 answers
52 views

Why is Magnetic Susceptibility not showing the expected transition in 2D&3D Ising Model?

I'm trying to code the Ising Model with the metropolis algorithm to study the ferromagnetic-paramagnetic transitions. The code seems to work ; the equilibration happens. While equilibrating, the ...
SSsaha's user avatar
  • 1
1 vote
1 answer
58 views

How to constraint the tangential gradient on a boundary in FEniCS?

The problem I'm considering is a 2D scalar PDE. The domain $\Omega$ is a disk with two holes $\partial\Omega_1$ and $\partial\Omega_2$ and an external boundary $\partial\Omega_0$. The PDE and boundary ...
Guillaume Faye-Bédrin's user avatar
1 vote
1 answer
143 views

Numerically solving the Advection-diffusion equation with no-flux boundary condition leads to violation of mass conservation

I am trying to solve numerically the advection-diffusion equation of the following form $$\frac{\partial C}{\partial t}=\alpha\frac{\partial^2 C}{\partial x^2}+\beta \frac{\partial C}{\partial x}$$ ...
Ornate's user avatar
  • 11
0 votes
0 answers
37 views

Find peaks method for finding elusive peaks

I'm currently utilizing the find_peaks function to identify peaks within this spectrum. However, despite consulting similar queries on Stack Overflow, my attempts to incorporate features such as ...
Manuel Borra's user avatar
0 votes
0 answers
42 views

How to calculate the numerical integration and plot the result in python?

I am trying to solve the question below in McQuarrie Physical-Chemistry book. The first step of the exercise, I solved. However, the second step involves a numerical integration. I can develop a code ...
Joao Victor Ferreira da Costa's user avatar
1 vote
0 answers
48 views

Converting an expression into an einsum

I have the following expression that I need to calculate for some matrices: $$ \sum_{k}c_{t,i,k}\sigma^\prime\left(w_tX_t+b_t\right)_k\left(\sum_\ell w_{t,k,\ell}\tilde{X}_t^{w,\ell}\right) $$ I could,...
Gummy bears's user avatar
0 votes
1 answer
66 views

BSplines from scipy not defined on whole range of the knots

I am looking at the construction of BSplines out of curiosity. I created a small code that uses scipy.interpolate.BSpline to create basic splines. I get the following basic splines for order 0, 1 and ...
edamondo's user avatar
  • 173
0 votes
1 answer
132 views

Auto differentiation with JAX in python and ForwardDiff.jl in Julia give matrices with different values but same structure. Are the results right?

Using ForwardDiff in Julia gives me the following values for 2 matrices I have tried to use JAX to auto differentiate the same function in Python but I am getting the following results for A and B ...
user693129's user avatar
2 votes
0 answers
71 views

How to solve this nonconvex problem in python

I have the following problem to solve minimize $$\sum_{i=1}^I\sum_{k=1}^Kx_{i,k}.$$ The constraints are as follows: $$\sum_{i=1}^I\sum_{j=1}^J\ln(c+x_{i,k}A_{i,j,k})\geqslant B_k,\forall k,$$ and $$\...
zdm's user avatar
  • 121
0 votes
0 answers
35 views

Using multiple bounds constraints parameters for a convolved gaussian fit

I'm currently analyzing XRF spectra, specifically focusing on the spectrum of (Pb). In XRF spectroscopy, the lines in the spectrum can often be effectively modeled by Gaussian distributions. Here, ...
Manuel Borra's user avatar
0 votes
1 answer
104 views

Converting large .tif files to zarr arrays

I have multiple .tif files which range from 500MB - 5GB. I need to convert them to zarr arrays and preferably write them to my disk. I have an aws ec2 linux instance with 32GB RAM. I have searched ...
PotterHead's user avatar
0 votes
0 answers
85 views

First and second component of fft for circle approximation to periodic curve

I wanted to understand how the fast fourier transform work in numpy and for this I tried apply it on $n$ points of an ellipse $t_k = \frac{2\pi}{n-1}k$ with $k=1...n$ $$f_k = f(t_k) = (acos(t_k), bsin(...
edamondo's user avatar
  • 173
0 votes
0 answers
52 views

Parallel vs Serial computing using Python Qutip. Why is serial faster?

I am trying to learn parallel computing using qutip's parallel_map function. I've tried to write a basic and simple code to understand the differences between parallel and serial calculation of ...
muzbi's user avatar
  • 1
0 votes
0 answers
50 views

Calculating a 2D Ewald sum for a multipolar expansion

I am attempting to calculate the potential of a particle at the center of an infinite two-dimensional lattice as per the following reference: Reference: Lambin, PH & Senet, P. Ewald Summation of ...
JasonC's user avatar
  • 43
2 votes
1 answer
120 views

Different Results for Double Pendulum

In this study, (Hidden Fractals in the Dynamics of the Compound Double Pendulum) the authors provide various fliptime fractals (of a double pendulum) for different length combinations. However, when I ...
MaximeJaccon's user avatar
0 votes
0 answers
24 views

Help in solving Quintessential scalar field using Steep Potential in cosmology

I am attempting to solve the differential equation $\ddot\phi + 3H\dot\phi + \dfrac{dV}{d\phi} = 0.$ For $V(\phi) = V_{0}e^{-\lambda\phi}$, where $V_{0} = 0.7$, $\lambda = 0.1$ and $V'(\phi) = \dfrac{...
user avatar
0 votes
0 answers
10 views

Is the following the correct implementation of VGG network?

As exercise I am implementing few fundamental networks. Specifically right now I am implementing VGG The code I've got at the moment is the following: class MyVGG(nn.Module): ...
user8469759's user avatar
1 vote
0 answers
56 views

How to simulate a multi propagation of a laser beam in atmospheric turbulence?

I want to simulate how a Gaussian beam would look like at the receiver plane when propagated through an atmospheric turbulence. For this I am using AO package. Since I didn't see any function for ...
Rima's user avatar
  • 111
1 vote
1 answer
46 views

Difference of tensors to construct a higher dimensional tensor in pytorch

Suppose I have two tensors $A_{i_1,\ldots,i_M}$ and $B_{j_1,\ldots,j_N}$ where $M \neq N$ in general. We can define a tensor $C_{i_1,\ldots,i_M,j_1,\ldots,j_N}$ by $$ C_{i_1,\ldots,i_M,j_1,\ldots,j_N} ...
user8469759's user avatar
3 votes
3 answers
97 views

How to implement the following operation in pytorch (tensor by equating indices)

I wasn't sure if I should post this on stackoverflow rather than here, but because I have to construct a specific tensor I think here is more suitable. I have 2 tensors, $x \in \mathbb{R}^{M \times N \...
user8469759's user avatar
0 votes
0 answers
38 views

Efficient sum of distributions (mixture distribution) and sampling

I manage to implement adaptive sampling by drawing samples iteratively from an update distribution which is represented by a mixture of two distributions, such that $$ρ_{new} = a * ρ_{old} + (1 - a) * ...
Zuba Tupaki's user avatar
1 vote
0 answers
84 views

Regarding the difference between Metropolis-Hastings and Wolff algorithm (synchronous vs asynchronous) applied to Ising Model?

I am trying to self-learn concepts at the intersection of physics and programming. When reading up on the Ising Model, I find that the typical programming tutorial (such as this one) covers the ...
user23358153's user avatar
2 votes
0 answers
53 views

Solving a system of non-linear equations to find relationship between arguments

I have a program that implements a multivariate function, call it $f = \mathcal{Q}(Z,v)$ that I can compute given $Z,v$. The $v$ variable is related to the $f$ variable by another relation, call it $v ...
haricash's user avatar
1 vote
2 answers
437 views

optimizing piecewise linear objective functions (perhaps non convex) with equality constraints

When I do my project, I need to optimize piecewise linear objective functions (perhaps non convex) with equality constraints. The piecewise linear objective function may be not convex like this in the ...
Yiyuan Chen's user avatar
0 votes
1 answer
97 views

Solving a polynomial with NumPy

I'm trying to do something that I thought would be very straightforward but somehow I'm struggling. I have a time series and I want to extrapolate it, assuming a linear trend, to forecast when will it ...
user avatar
0 votes
0 answers
97 views

How to minimize a numerical integration in python?

I need some help to minimize a numerical integration. It's about a classical problem in physics (hydrogen atom). It can be solved analytically but I need to solve it numerically in Python. We have an ...
Rubens Filho's user avatar
0 votes
0 answers
62 views

I am currently working on a data ana that involves examining trends across 14 var. These var have distinct scales, making visualization a bit diff

Scaling Issues: Many of the columns I'm analyzing are in different scales, which makes it challenging to visualize them together effectively. Visual Representation: I initially attempted to use ...
yashus123's user avatar
0 votes
0 answers
69 views

Singular Matrix Error in Incomplete LU Decomposition

I’m currently working on solving the following PDE: $$\begin{equation} -(\mu_x \frac{\partial^2 u}{\partial x^2} + \mu_y \frac{\partial^2 u}{\partial y^2}) = f(x, y)\end{equation}$$ Where a right hand ...
blov's user avatar
  • 43
2 votes
0 answers
96 views

Numerical solution for inviscid Burgers' equation seems to have no breaking time?

So I'm trying to use the Lax-Friedrichs method to solve the inviscid burgers' equation with initial condition $$u(x,0) = \sin(x)$$, using $$u_m^{n+1} = \frac{1}{2}(u_{m+1}^n + u_{m-1}^n) - \frac{\...
Applesauce44's user avatar
0 votes
0 answers
59 views

Solving AU = F using linalg.cg results in 0 iterations

I am working on solving the following PDE: $$\left(\mu_{x}\frac{\partial^{2}u}{\partial x^{2}}+\mu_{y}\frac{\partial^{2}u}{\partial y^{2}}\right)=f(x,y) \tag 1$$ Which is then discretised: $$- \mu_{x} ...
blov's user avatar
  • 43
1 vote
1 answer
74 views

Numerically computing envelope of Gibbs oscillation

If I numerically compute the envelope of $\sin(\pi t)$ using a Hilbert transform, I obtain exactly what I expect: If I do the same for $\mathrm{sinc}(t)$, still I obtain an envelope which agrees with ...
user14717's user avatar
  • 2,155
2 votes
1 answer
330 views

Large set of nonlinear equations in Sympy

I have a set of 6 nonlinear equations, and using Sympy I find the values of the 6 unknowns. This works perfectly and it directly gives the exact solution, using sympy.solve to be specific. Now I ...
je2703's user avatar
  • 21
2 votes
1 answer
189 views

Solving non-linear partial differential equation numerically: $u_{xx}+u_{yy}=\mathrm{e}^{u}$

To start with, I need to solve this partial equation numerically, but I do not know how to do that. If I try a finite difference method, I face a problem that $u_{i,j}$ is also located in exponential, ...
Evgeny's user avatar
  • 21
3 votes
0 answers
148 views

Numerical integration in Fourier space over 3D grid

I am attempting to implement a model outlined in this paper: General magnetostatic shape–shape interactions Background This model allows the calculation of magnetostatic interaction energies between ...
JasonC's user avatar
  • 43
1 vote
0 answers
40 views

Implementation of operator splitting method for Wigner equation

I am dealing with the integro-differential equation for Wigner function, $$\frac{\partial f}{\partial t}+p\frac{\partial f}{\partial x}+\\+\frac{1}{\chi}\left\{\int_{-\pi}^{+\pi}dy\,\int_{-\infty}^{+\...
Artem Alexandrov's user avatar
1 vote
1 answer
81 views

Does anyone know how to add a forcing term at the center of a cicular membrane?

I am here once again searching for wisdom, as some of you might notice I asked a related question a few days ago. And now I am struggling to add a forcing term at the center of the membrane, in order ...
Manuel Borra's user avatar
2 votes
1 answer
200 views

Need help with the python code: Calculating Madelung constant CsCl crystal structure

Need help with the code to estimate the Madelung constant for CsCl lattice: Cs at (0,0,0) Cl at (0.5, 0.5, 0.5) Answer: Converged value I am getting is 0.465. ...
chola's user avatar
  • 21
0 votes
1 answer
203 views

Solving the wave equation for a circular membrane in polar cordinates

As you see this mode is not right, unless for what i understand And the initial conditions were ...
Manuel Borra's user avatar
2 votes
0 answers
110 views

Newton-Raphson with Zeroth-Order Continuation is not Converging

I am trying to solve this system of nonlinear equations using Newton-Raphson method with continuation (zeroth-order continuation). $F_1(x, y, \xi, \nu) = \left(1 - \frac{1}{\nu}\right) \left(1 - x\...
Abdeljalil's user avatar
2 votes
2 answers
949 views

Numerical implementation of ODE differs largely from analytical solution

I am trying to solve the ODE of a free fall including air resistance. I therefore defined my ODE as: def f(v, g, k, m): return g - k/m * v**2 which in my ...
Axel's user avatar
  • 123
4 votes
1 answer
345 views

How to efficient solve $e^{-tA} x =b$, where A is a very sparse matrix

I am going to solve an equation containing an exponential matrix $e^{tA} x =b$, which can be obtained naturally through $x=e^{-tA} b$. A is a 1million $\times$ 1 million matrix with stores 7.15 ...
Owen Jun's user avatar
  • 141
4 votes
1 answer
664 views

Is my differential equation solving code wrong?

I am trying to simulate LLG equation without damping. The equation is $$\frac{d\vec{m}}{dt} = \vec{m}\times\vec{H}$$ I am solving in spherical coordinates as LLG equation is known to have problems in ...
User's user avatar
  • 141
1 vote
0 answers
64 views

preconditioning least square in python?

For a nonsymmetric matrix, we can solve { A^T @ A x = A^T b } by lsqr or cgls or something else. Usually it will be slow, so we need a preconditioner either ilu, multigrid or something else. Is there ...
Alvin's user avatar
  • 11
0 votes
1 answer
288 views

Questions on the theory of distributed numerical algebraic computation

I'm trying to build a pure python distributed numerical algebra computation kernel based on GPU. but after I've learnt most of the software engineering, I realise that I'm seriously lacking in ...
Haitao Xiao's user avatar
1 vote
1 answer
120 views

Improvement to naive gradient descent implementation for the Thomson problem

I have a Python program (available on github) that uses naive gradient descent to find approximate solutions to the Thomson Problem. It works surprisingly well, but I've been wondering if there's a ...
Martin C.'s user avatar
  • 229
1 vote
1 answer
185 views

Calculating Madelung constant via Ewald summation

I am attempting to calculate the Madelung constant for NaCl using an Ewald sum derived by Nijboer. There are other methods and published codes to do this, but I am specifically interested in working ...
JasonC's user avatar
  • 43
0 votes
0 answers
113 views

Plotting ground Tracks with Python only using trigonometry

I'm currently studying aerospace engineering, and I'm attempting to create a ground track plot in Python using data from a TLE file. I'm doing this without relying on explicit packages like AstroPy or ...
ed190's user avatar
  • 1

1
2 3 4 5
19