Questions tagged [python]
A general purpose high-level programming language that emphasizes ease of code syntax and readability.
898
questions
0
votes
0
answers
23
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 ...
1
vote
1
answer
44
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 ...
1
vote
1
answer
59
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 ...
-3
votes
1
answer
33
views
0
votes
0
answers
21
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 ...
1
vote
0
answers
18
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 ...
0
votes
0
answers
41
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 ...
0
votes
1
answer
57
views
What is the code in Python for calculating values from factorial relations?
I would like to make a table of values of (for example) Stirling numbers of the first kind.
Stirling number of the first kind $c(n,k)$ satisfies the following factorial relation:
$$x(x+1)(x+1)...(x+n-...
0
votes
0
answers
54
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 ...
1
vote
1
answer
147
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 ...
5
votes
1
answer
727
views
Taking derivative using FFT
I would like to calculate derivative of a given function ( a 1D array) using Array. Here is the code
...
2
votes
1
answer
79
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 ...
2
votes
1
answer
52
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 ...
1
vote
0
answers
67
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 ...
5
votes
3
answers
392
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? ...
2
votes
0
answers
73
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}...
2
votes
1
answer
76
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 ...
2
votes
2
answers
168
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 ...
0
votes
0
answers
21
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:
...
6
votes
1
answer
148
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 ...
1
vote
2
answers
117
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,...
0
votes
2
answers
147
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 ...
0
votes
0
answers
41
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 ...
2
votes
0
answers
96
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 ...
0
votes
0
answers
35
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}}...
1
vote
0
answers
25
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 ...
0
votes
0
answers
18
views
How can you plot a value in PYTEARCAT?
I've been working with Tensor calculus using the Python module PYTEARCAT. (See: https://arxiv.org/abs/2106.15016 and https://github.com/pytearcat/pytearcat.) It calculates quantities such as the Ricci ...
3
votes
0
answers
115
views
Python code of explicit method of a nonlinear a BVP
I am trying to have a Python code for the following nonlinear BVP:
$$\frac{\partial N}{\partial t}=\frac{\partial^2 N}{\partial x^2}+N(1-N)-\sigma N$$ $$N(0,x)=\sin(2\pi x)$$
$$N(t,0)=0 \hspace{3mm}N(...
1
vote
1
answer
52
views
Possible bug with scipy.optimize SHGO sobol: TypeError: <lambda>() takes 1 positional argument but 3 were given
I have been trying to perform some global optimization with SciPy optimizer SHGO
and I've had issues with the sampling method 'sobol'. Specifically, I get an error ...
2
votes
2
answers
88
views
How do I evaluate the numerical solution at a point that isn't on the mesh
I'm trying to code a fixed-point method to solve the following system using scipy.integrate
$$
u_{n+1}(s)=\int_0^TK_\lambda(t,s)\left(\lambda u_n(t)+\sigma(t)+f(t, ...
0
votes
2
answers
42
views
How to program the convergence of a sequence of systems of integral equations using Scipy
I'm trying to solve the problem
where $u_n$ and $v_n$ are sequences that converge to the solution $u$ and $v$ and $\lambda$, $\sigma$, $f$ and $g$ and K_lambda are all given.
I thought of using the ...
2
votes
2
answers
347
views
Problems solving 2D heat equation using physics-informed neural networks
I am trying to solve 2D heat equation using the physics-informed neural networks approach. The training loss is decreasing, but my final network outputs make no sense. I am using Python/Pytorch.
2D ...
-1
votes
1
answer
26
views
How to generate p Sample of GGM of dimension m, for parameter : the weight, the means and the covariance?
after searching in the python numpy, scipy and sklearn module, there is no function who can generate p samples of a gmm (gaussian mixture model) for parameter means, covariances and the weight of each ...
1
vote
1
answer
113
views
QR algorithm for eigenvalues and eigenvectors of large symmetric matrices
I am trying to write a QR algorithm in Python for eigenvectors and eigenvalues finding for large symmetric matrices,
My initial thought was to use Householder transformation with a Wilkinson shift on ...
1
vote
1
answer
109
views
Python libraries for larges scale optimization/rootfinding
I have been dealing with the standard libraries of scipy.optimize for rootfinding and optimization problems, but the problems i want to solve are very large, which makes the standard solvers run out ...
0
votes
0
answers
63
views
Encountering blow-up when solving the one-way heat equation using Lax-Wendroff
This is my first time attempting to implement a finite difference method for a PDE in Python, and I am having a bit of trouble. The PDE I am trying to solve is as follows:
$$
\begin{cases}
...
0
votes
0
answers
36
views
What is meant exactly by the domains in this context and how can I simulate their size?
I was working on a problem from "Computational Physics using python: Chapter 17." The problem is concerned with simulating the thermodynamics behind the spin of electrons and the resulting ...
0
votes
0
answers
69
views
Deviation between Analytic DFT and FFT in Python
Within my work, I am trying to compare analytically retrieved power spectra with ones calculated from fft packages in python.
The problem I have, is that the analytic form of the peaks I derived does ...
3
votes
1
answer
326
views
Time and memory required to diagonalize a 18000 by 18000 matrix using numpy in python
Can someone give an estimate of the Time and memory required to diagonalize a 20000 by 20000 complex hermitian matrix using numpy in python ?
1
vote
0
answers
90
views
Solving 2D Poisson equation with mixed boundary conditions in Python
I am trying to numerically solve the Poisson's equation
$$
u_{xx} + u_{yy} = - \cos(x) \quad \text{if} - \pi/2 \leq x \leq \pi/2 \quad \text{0 otherwise}
$$
The domain is the rectangle with vertices ...
2
votes
0
answers
110
views
Solving 2D Poisson equation with Dirichlet boundary conditions in Python
I am trying to solve the following PDE:
$$
\begin{align*}
u_{xx} + u_{yy}
=
\begin{cases}
- \cos(x) \quad -\pi/2 \leq x \leq \pi/2, \\
0 \quad \text{otherwise}
\end{cases}
...
2
votes
1
answer
99
views
Need help to fully understand SciPy's odeint's reported step sizes, eval times, # of funct calls & total proc. time (re. question in Astronomy SE)
A recent question in Astronomy SE Numerical Programming using odeint takes more than 17 minutes got me interested in looking closer at SciPy's odeint.
The problem is a modified orbital mechanical ...
2
votes
1
answer
224
views
Motion of the particle trapped in potential
I have lots of difficulties trying to make a phase plot for the motion of the particle trapped in Lennard-Jones potential:
$$V(q)=\epsilon\left[\left(\frac{q_\mathrm{min}}{q}\right)^{12}-2\left(\frac{...
0
votes
0
answers
53
views
Solving Laplace for Velocity Potential in Constricted Channel
I am trying to solve the 2D Laplace equation numerically to give the velocity potential of a fluid flowing in a channel with a constriction:
$u_{xx}+u_{yy}=0$
There is a constriction in the channel at ...
2
votes
0
answers
86
views
Scipy.root not converging even when provided with initial guesses very close to solution
I've made a previous question here and also in SO wondering why only the fsolve solver converges for the simple one dimensional unsteady conduction problem
$$ \frac{\partial T}{\partial t} = \alpha \...
1
vote
0
answers
65
views
How to include zero flux boundary conditions?
I am trying to solve the following differential equation in the domain of $\theta \in [0, 2 \pi]$ using finite differences scheme:
For $0< \theta \leq \pi$
\begin{align}
\rho_i^{n+1}=\rho_i^{n}+D\...
1
vote
0
answers
88
views
Interface condition for 1D Helmholtz equation using finite element method
I want to implement a 1D Helmholtz equation with jump condition. The domain is $x=[0,1]$ and both ends have Dirichlet boundaries($p$=0). The 1D strong formulation is;
$$c^2\nabla^2p + w^2p=0 \qquad \...
0
votes
1
answer
134
views
Solve 1st order ODE in using `scipy`
I've been trying to solve the following equation
$$
y(t)=-A\cdot\frac{\mathrm{d} y}{\mathrm{d} t}+B\cdot\left(\frac{\mathrm{d} y}{\mathrm{d} t}\right)^{2}+C
\\
y(t=0)=y_{0}\\
$$
where $A$, $B$, and $C$...
0
votes
0
answers
56
views
Eigenvalues of same operator expressed in two different orthonormal basis are coming out different
I have an operator $H$. I express $H$ as a matrix in the orthonormalized $\{ |e > \}$ basis. Then I diagonalize it to obtain eigenvalues, let's say for example $H$ is $6 \times 6$ and the ...
0
votes
0
answers
42
views
Grid search for bi-level optimization
Apologies if this isn't the best place to ask this question, and further apologies for such a basic question (I am a secondary school graduate and have not learned very much yet). Please direct me to ...