Questions tagged [python]

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

Filter by
Sorted by
Tagged with
1 vote
1 answer
43 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
75 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
36 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
70 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
51 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
396 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
78 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 ...
astrojuanlu's user avatar
  • 1,187
0 votes
0 answers
88 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
53 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
77 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
58 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
72 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
188 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
173 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
2 votes
0 answers
72 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
  • 31
1 vote
0 answers
38 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
76 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
140 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
161 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
107 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
939 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
320 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
  • 131
4 votes
1 answer
658 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
58 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
285 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
115 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
134 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
  • 31
0 votes
0 answers
61 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 vote
0 answers
51 views

numerical calculation of haldane model arm chair edge states

hello I am trying to numerical simulate the band structure of the one-dimensional periodic arm chair edge states, I use the pybinding model to construct and ...
yangxing844's user avatar
0 votes
0 answers
48 views

Nanograd differentation; what is going inside the python code

I am reading up on deep learning and I am trying to understand the backpropagation methods in python nanograd. See; https://github.com/rasmusbergpalm/nanograd This is a method for computing the ...
economist101's user avatar
1 vote
1 answer
102 views

What is the code in Python for calculating values from polynomial relation for the Stirling numbers of the first kind?

I would like to make a table of values of a sequence similar to Stirling numbers of the first kind and for the Stirling numbers of the first kind. Stirling numbers of the first kind $c(n,k)$ satisfy ...
User303131's user avatar
0 votes
0 answers
91 views

Solving system of ODEs, where time derivative approaches infinity due top initial condition

I am trying to solve a problem in python using scipy's solve_ivp. The system of ODEs I am trying to solve is for coupled where I am solving for two time-dependent ...
HWIK's user avatar
  • 23
1 vote
1 answer
380 views

Float equality tolerance for single and half precision

Suppose the metric is abs(a-b) <= rtol * max(abs(a), abs(b)) i.e. math.isclose with ...
OverLordGoldDragon's user avatar
5 votes
1 answer
790 views

Taking derivative using FFT

I would like to calculate derivative of a given function ( a 1D array) using Array. Here is the code ...
learning_physics's user avatar
2 votes
1 answer
116 views

Weights for equidistant samples in power law fitting

I am working on fitting analytical curves to experimental data obtained in real viscoelastic tests (in fact, static creep tests). The setting of the problem is: the experimental data I have is a set ...
ren1's user avatar
  • 23
2 votes
1 answer
130 views

2D integrals in Python with specified points of interest

Note: This is my first question on stackexchange; please tell me if I'm doing something incorrectly. I am trying to calculate a series of a 2D integrals in Python with an integrand that has several ...
Feathers's user avatar
1 vote
0 answers
172 views

Using solve_ivp for a PDE: how to handle multiple time-dependent variables?

I am trying to build a Python code that solves a set of coupled differential equations which will be spatially discretized by the method of lines advancing in time. I am planning to use ...
Ziad Nasef's user avatar
5 votes
3 answers
412 views

Packages suitable for numerical optimization of functions with discontinuous gradient at the point of minimum

Are there packages for numerical optimization in julia or python, or in any other system for scientific computing, capable of taking into account the discontinuity of gradient at the minimum point? ...
Gec's user avatar
  • 153
2 votes
0 answers
97 views

How can we symbolically working out $\phi^4$ theory green's function/propagator and consequences in python?

I am having some difficulty calculating Green's function symbolically in Python for $\phi^4$ theory. The specific rendition of the $\phi^4$ theory I have in mind can be written as follows. $\mathcal{L}...
kevin Tah N.'s user avatar
2 votes
1 answer
115 views

Tools to compare two matrices with same dimensions

Context: I have two 3D non-random matrices that have the same dimensions. These matrices represent satellite images with 1 band, so their values are strictly positive. They both present areas that ...
Nihilum's user avatar
  • 121
2 votes
2 answers
291 views

Solving IVP backward in time via python

I'm having difficulty solving an initial value problem (IVP) in Python backwards in time. The code is at the end of this post. First, please let me state my simplified problem. The forward IVP is ...
JesseJC's user avatar
  • 21
0 votes
0 answers
25 views

Matching the limits of integration with the proper variables in a complicated case when using scipy.integrate.nquad

I need to integrate expressions containing powers of the function: ...
ale victor's user avatar
6 votes
1 answer
254 views

Accelerating the computation of scipy.sparse.linalg.expm_multiply

I have a tridiagonal antiHermitian matrix ($-i*Hami*t$) with nonzero elements only along the upper diagonal and lower diagonal, and the goal is to know the action of exponential of such matrix on a ...
code437's user avatar
  • 63
1 vote
2 answers
380 views

How should I solve generalized eigenvalue problems in Python? (Orr-Sommerfeld equation)

I am trying to solve the Orr-Sommerfeld equation numerically, using the techniques given in this article. This leads to solving a generalized eigenvalue problem, that is, given two matrices $\mathbf A,...
K.defaoite's user avatar
0 votes
2 answers
160 views

Approximating the solution of a non-linear ODE using Python

This is my first time asking a question here, so please tell me if I have made a mistake or if anything is unclear. I am working on my high school research project on the motion of a ball falling ...
user1193197's user avatar
0 votes
0 answers
84 views

what is the proper way to update the XY model for a Metropolis MC simulation

I am trying to do a 2D simulation of the classical XY model in order to observe vortexes in the system. I am not really interested at the moment in calculating variables such as Magnetization because ...
Mephistopheles Faust's user avatar
2 votes
0 answers
132 views

How can I incorporate angular momentum in this code?

I'm currently working on the 3-body problem, and I was writing a code to plot the trajectories of all 3 bodies while also manipulating the angular momentum of the system. I found a code online and ...
Belal Bahaa's user avatar
0 votes
0 answers
40 views

Verification of a Function Definition in Python

I want to write a function $f$ and it is defined as $f = - \nabla \cdot(|\nabla u|^{p-2} \nabla u) $ and I exact solution $u(x) = \tilde{u}(r) = 1 - \frac{p-1}{p-2} \left( s^{p/{p-1}} - (1-s)^{p/{p-1}}...
User124356's user avatar
1 vote
0 answers
30 views

How can the current-voltage relationship of a series of tunneling junctions be most easily computed?

I'm working on a research project with my professor where we're trying to figure out how to determine the necessary semiconductor composition for a solar cell to have a particular bandgap in order to ...
Mikayla Eckel Cifrese's user avatar

1
2 3 4 5
19