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

Heat Equation for fast source with FiPy

I'm trying to solve the following differential equation with FiPy, basically laser irradiation on a surface $$ \rho_{s}C_{p,s}\frac{\partial T}{\partial t} = k_{s}\frac{\partial^{2}T}{\partial x^{2}} +...
clope99's user avatar
  • 11
1 vote
1 answer
55 views

How to solve three coupled differential equations in python using RK-4 and shooting method? or using solve_bvp?

I am trying to solve three coupled differential equations in Python. I am using RK-4 techniques with Shooting method. I am trying to plot the f and N functions. ...
Prosenjit Paul's user avatar
0 votes
0 answers
20 views

Use of scipy.linalg.cython_lapack.dgbsv in cython script

I was working into accellerating a solver for baded matrix using cython. The base case is the following pure python code : ...
GMV871's user avatar
  • 35
2 votes
1 answer
125 views

Efficient Solver for Solving a Large Linear System Sequentially of a Positive Definite Matrix

In my case, I am solving $AX=B$ repeatedly, but the solution usually doesn't change much. So it'd probably be faster than me when I start from the previous solution and iterative, rather than solving ...
Taylor Fang's user avatar
1 vote
1 answer
129 views

Preconditioner Implementation with matrix-free methods (sparse iterative solvers)

How can I define preconditioners (SPILU, SPAI, etc.) for sparse iterative methods (TFQMR, GMRES, CGS, etc.) for the matrix-free left-hand side? I defined $Ax=b$ using matrix-free $A$ (with ...
Furk's user avatar
  • 11
3 votes
1 answer
608 views

Overflows and underflows in Python

I’m writing some Python code using NumPy. Since I got an overflow warning, I decided to check for underflows as well at all places in the code, using ...
NNN's user avatar
  • 832
1 vote
1 answer
185 views

Coupled Partial Differential Equations

I'm trying to solve the following system of coupled differential equations, the two-temperature model for $e$ = electrons and $l$ = lattice. $$ \rho_{e}C_{p,e}\frac{\partial T_{e}}{\partial t} = k_{e}\...
clope99's user avatar
  • 11
0 votes
1 answer
92 views

optimize this python code that involves matrix inversion

So I have this line of code that involves a matrix inversion X = A @ B @ np.linalg.pinv(S) $A$ is an $n$ by $n$ matrix, $B$ is an $n$ by $m$ matrix and $S$ is an $...
Taylor Fang's user avatar
4 votes
1 answer
108 views

How can I efficiently find an anti-symmetric generator of a special orthogonal matrix?

Given a special orthogonal matrix $O$ (i.e: $OO^T = 1$ and $\det(O) = 1$), I am trying to efficiently find a matrix $X$ such that $O = e^X$ and $X = -X^T$ using Python (NumPy & SciPy). One obvious ...
Solarflare0's user avatar
0 votes
0 answers
21 views

What is the most accurate way of computing the evaluation time of a neural network model?

I am training some neural networks in pytorch to use as an embedded surrogate model. Since I am testing various architectures, I want to compare the accuracy of each one, but I am also interested in ...
HWIK's user avatar
  • 23
2 votes
0 answers
109 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
35 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
58 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
71 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
236 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
55 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
61 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
54 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
84 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
185 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
97 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
41 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
241 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
87 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
59 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
58 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
125 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
79 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
49 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
139 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
40 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
94 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
55 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
489 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
120 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
109 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
63 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
83 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
112 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
61 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
75 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,165
2 votes
1 answer
441 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
192 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
173 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
43 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
236 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
213 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

1
2 3 4 5
19