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
0answers
29 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/...
2
votes
0answers
33 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 ...
-1
votes
0answers
42 views

Numerical difficulties solving 1D steady-state, real gas pipe-flow problem (I think) [closed]

I am trying to implement a 1D, steady-state, real gas (compressibility factor) pipe flow model in Python using Pyomo + SCIP. It basically amounts to solving a DAE system. The formulation is an adopted ...
7
votes
0answers
92 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 ...
2
votes
1answer
126 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} &...
0
votes
0answers
56 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 ...
1
vote
1answer
36 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, ...
4
votes
1answer
98 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 -...
0
votes
0answers
20 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}{(\...
0
votes
0answers
20 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: $$ -...
-1
votes
0answers
25 views

I need help with the Trotter-Suzuki method [closed]

I am new in the field of computational science, and I have some difficulties when I tried to compute the Trotter-Suzuki method in python. I have defined / decomposed the matrices but when I plotted it,...
1
vote
0answers
93 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 ...
1
vote
1answer
144 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 ...
2
votes
0answers
56 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 $$...
3
votes
0answers
93 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 ...
3
votes
1answer
89 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}...
0
votes
0answers
42 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 ...
1
vote
0answers
64 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 ...
3
votes
1answer
176 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....
4
votes
0answers
48 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 ...
4
votes
1answer
169 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 ...
1
vote
1answer
63 views

solve_ivp doesn't work with toms748

I have the following code ...
2
votes
1answer
131 views

SciPy odeint giving different results with matrix multiplication

I've asked this at stackoverflow but maybe this community will have a better idea of the answer. I'm currently trying to develop a function that performs matrix multiplication while expanding a ...
1
vote
1answer
118 views

Numerical Solution of the Schrödinger equation for hydrogen

I'm trying to solve the Schrödinger equation for the hydrogen atom in the following form numerically: $$\left[-\frac{\hbar^2}{2m}\frac{d^2}{dr^2}+V(r)+\frac{\hbar^2l(l+1)}{2mr^2}\right]R(r)=ER(r).$$ ...
3
votes
1answer
108 views

Solving and Plotting Mutualism Model in Python

I am a beginner in programming. I need to program a mutualism model of two species in python that would solve and graph using the following equations: $$ \frac{dN_1}{dt} = N_1(r_1 - e_1N_1 + \alpha _{...
0
votes
0answers
30 views

Gridline cutouts after FFT and iFFT on Python

EDIT: I think I messed up on the coordinates of $(p,q)$. Num was missing a multiple of $2\pi/N$. Assuming my interpretation of DFT isn't wrong. I am currently using FFT to run Fresnel Diffraction as ...
2
votes
0answers
103 views

Split Operator 2D-->3D

I am trying to modify my simulations on population dynamics using the split-operator method from 2D two-level real Hamiltonain $$H_{2D} =T(x,y)\otimes1_2 +\begin{pmatrix} -z & y\\ y & z\\ \...
1
vote
0answers
36 views

Anyway to escape ODEintWarning (scipy)?

I am trying to fit a differential equation to some data and obtain the parameters of the underlying model. This requires me to try out various parameter values, but this often gives me an ...
4
votes
1answer
581 views

Why is my curve_fit not producing the covariance matrix and the correct values for the unknown variables?

I am trying to fit supernova data into a scipy.curve_fit function. However, when my code runs, the values of the unknown variables given by ...
2
votes
2answers
169 views

Calculate determinant of unitary matrices based on SVD implementation

I have a real square matrix $X$ which I need to perform a Singular Value Decomposition on. Now, performing the operation $$ X = USV^T $$ as $U$ and $V$ are orthogonal, we know that $\det(X)=\pm\det(S)$...
1
vote
1answer
85 views

Finding the root of an equation (divergence at some points)

I am trying to solve this equation for $v_{Sl}$ in the range $[0.001,1]$ to obtain the values of $\delta_l$. I have tried Fsolve with python, which gives results ...
0
votes
0answers
21 views

Using Pymc3+Theano+astropy for Bayesian inference with integral expressions

This is my first time using Pymc3 or Theano, so I apologize if this question is straightforward. I'm interested in using Bayesian inference to see how effective the (non) observation of something can ...
3
votes
1answer
315 views

A method for finding the number of eigenvectors with a given, known eigenvalue

Is there a method for finding the number of eigenvectors with a given eigenvalue? I do not need the eigenvectors themselves, and to find the eigenvectors seems quite tough, given the comments on the ...
1
vote
0answers
52 views

How do people deal with resized grid steps while numerically integrating using discrete Fourier Transform?

I am trying to simulate light propagation on python using FFT following the Fresnel diffraction equation given on Wikipedia: The problem with this is that the output matrix from the DFT would be ...
4
votes
0answers
43 views

Pass forward intermediate results during iterative optimization

To investigate a counter-current flow heat exchanger while considering temperature dependent physical properties (such as specific heat $c_\textrm{p,i}$, heat conductivity $\lambda_\textrm{i}$, ...
1
vote
0answers
36 views

How do you correctly implement Scipy's FFT procedures to produce a low-pass filter - image processing

I'm following this low-pass filter example in the text "Image Operators: Image Processing in Python 1st Edition" by Jason M. Kinser, but can't seem to duplicate their results. The text's ...
0
votes
1answer
75 views

What is the meaning of triangles color in the result of Tipping Problem in scikit-fuzzy (fuzzy logic)?

I am following this example https://scikit-fuzzy.github.io/scikit-fuzzy/auto_examples/plot_tipping_problem_newapi.html from documentation of scikit-fuzzy library,but I have a question in the figure ...
1
vote
0answers
37 views

2D DFT for lower frequencies only; is there something significantly faster than numpy.fft.fft2 (throwing away high frequencies)?

I do a lot of 2D discrete FFT in python using np.fft.fftshift(np.fft.fft2(y)), then throw away 90% or more of the array, keeping only the central low-frequency area....
3
votes
2answers
146 views

Is there a Python version of the ODE tool pplane?

This is the same question as this one, except for Python instead of Mathematica. Basically, the MATLAB software PPLANE is a staple in ODE courses. Is there a Python equivalent? I don't know much about ...
1
vote
0answers
44 views

Is there a way to generate a sample $(X_i, Y_i, Z_i)$ from custom distribution?

I'm newbie here. I'm wondering if it's possible to generate $(X_i, Y_i, Z_i)$ from my own distribution function? I know that there is a way to make own class for 1D variable. But what about 3D case?
0
votes
1answer
120 views

Lagrange multiplier for boundary conditions in pure Neumann problem

I'm trying to solve $-u''=\cos(2 \pi x)$ with boundary conditions $u'(0)=u'(1)=0$ and the constraint $\int_{0}^1 u = 0$ I have to use linear finite elements, so let's assume that I have $M$ degrees of ...
1
vote
0answers
179 views

How to compute the Eigenvalue and Eigenstates of Quantum well with Effective mass using finite difference method in Python?

I want to compute the eigenvalues and eigenstates of a quantum well with different effective masses of electron in the barrier and in the quantum well. As can be seen [1]: https://github.com/mholtrop/...
1
vote
1answer
297 views

solve_ivp from scipy does not integrate the whole range of tspan

I'm trying to use solve_ivp from scipy in Python to solve an IVP. I specified the tspan ...
4
votes
2answers
156 views

Computation of the tensor of curvature on surface mesh

Is there a formula which enables the computation the tensor of curvature knowing the following at each vertex and cell of a triangulated mesh: Normal vector Two arbitrary vectors in the tangent space ...
0
votes
1answer
34 views

Logistic growth curve using scipy is not quite right

I'm trying to fit a simple logistic growth model to dummy data using Python's Scipy package. The code is shown below, along with the output that I get. The correct ...
4
votes
2answers
235 views

Storing large amounts of interpolation data

Overview and Prior Research I am looking for a way store a (in principle arbitrarily) large "3D-table" for interpolation/ lookup in combination with python. I have considered CSV files, but,...
0
votes
0answers
41 views

Numerically solving schrodinger equation [duplicate]

Consider the potential given above: $$U(r) = \frac{U_0}{\exp[(r - r_0)/\epsilon] + 1}\, .$$ How to solve the Schrodinger equation with this potential numerically and find the eigenvalues?
7
votes
1answer
159 views

Why Is This Python Code Faster Than Fortran Wrapper with F2PY?

I am writing a proof-of-concept implementation of Newton's method for minimizing the negative log-likelihood term in a logistic regression model. I'm comparing the performance of a native python ...
3
votes
0answers
107 views

Help with restart functionnality in sef-made GMRES solver in python

I am new to this forum and to computational science in general. I started to learn numerical liner algebra on my own and would like to code a GMRES solver in python (no preconditioner for the time ...

1
2 3 4 5
16