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

Use BIConjugate Gradient with incomplete LU decomposition as preconditioner [closed]

see my question over here: https://stackoverflow.com/questions/69706672/use-biconjugate-gradient-with-incomplete-lu-decomposition-as-preconditioner What can I do to solve this problem?
1
vote
0answers
22 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 ...
-1
votes
0answers
35 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
24 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
92 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? Sample outputs from ...
1
vote
0answers
37 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
66 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
votes
0answers
23 views

Curve Fitting convoluted-exponential-gaussian-probability-function from Igor Pro

So I recently created this post which I answered about plotting point from a convoluted-exponential-gaussian-probability function. from: Convoluted exponential gaussian probability function from Igor ...
-1
votes
0answers
27 views

Can constants and parameters in a Gekko model be simply Python variables?

I'm new to Gekko and I noticed that Gekko will still run even if I don't define fixed values in my model as Gekko constants and parameters. For example, this code still runs and gives an answer: ...
1
vote
0answers
119 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
111 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
1answer
106 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
28 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
211 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
39 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
146 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
47 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 ...
9
votes
1answer
465 views

How to solve a second order differential equation (diffusion) with boundary conditions using Python

I am having trouble implementing a model from a publication. Huang, K-L.; Holsen, T.M.; Selman, J.R. Ind. Eng. Chem. Res. 2003, 42, 15, 3620–3625 scihub link: https://sci-hub.se/10.1021/ie030109q I ...
0
votes
2answers
118 views

Implementation of $[X, \cdot]$ as an $n^2 \times n^2$ matrix, where $X$ is an $n \times n$ matrix

Let $M_n(\mathbb{R})$ denote the set of $n\times n$ matrices with real entries. I have an $n\times n$ matrix $X\in M_n(\mathbb{R})$, and I would like to implement the linear operator $[X, \cdot] : M_n(...
3
votes
1answer
102 views

Parameters estimation with fewer variables than parameters

I am trying to estimate parameters, 4 of them, by fitting a system of 3 ordinary differential equations. I am using a model published that was using 3 parameters and gave a good fit to the data, and I ...
-1
votes
1answer
1k views

Error in python (jupyter): index 1 is out of bounds for axis 0 with size 1 [closed]

I am an amature in python, I wrote a simple code in jupyter. But it is giving an error. I want to plot a function: ...
3
votes
2answers
172 views

How to solve the integral-like energy equation with Sagdeev potential numerically in Python?

I am trying to numerically solve equation (6) of Lakhina 2021 in Python. The equation is $$\frac{1}{2}\left(\frac{d \phi}{d\xi}\right)^2 + S(\phi, M) = 0\, .$$ The Sagdeev potential expression is ...
2
votes
1answer
763 views

Error in Simpson's 3/8 rule is higher than that of Simpson's 1/3 rule

For a given function $f(x)$, I have tried to find its numerical integral using Simpson's 1/3 and Simpson's 3/8 rules. I then compare the solution from the numerical quadratures to the analytical ...
2
votes
2answers
168 views

Single hexahedral element stiffness matrix problem, help me find the mistake

Attached below is some code I wrote to solve a basic problem: finding the node displacements of a cube with two vertices constrained (vertices 6 and 7 with coordinates ...
1
vote
2answers
36 views

scipy odeint: excess work done on this call depending on initial values even with analytically solvable ODE

I am trying to solve a differential equation in the form: dx/dt = funct(x) using scipy odeint. However, for some initial values, I get a "ODEintWarning: Excess work done on this call", even ...
0
votes
0answers
37 views

Plotting the motion of a positive charge in a cylindrically symmetric magnetic field

I want to plot the motion of a positive charge in a cylindrically symmetric magnetic field. I am assuming a cylinder around the z-axis, with the magnetic field going in clockwise direction. The B-...
12
votes
1answer
5k views

Meaning of "-0.0" in Python?

We are finding in Python some occasional errors in our coordinate transforms and other similar computations that produce a result of -0.0. What purpose does this ...
2
votes
0answers
38 views

Adding a "cost term" to a linear regression, so solution values are minimized

I'm using Python's optimize.lsq_linear method to run a linear regression with the bounds set between 0% and 100% power usage. ...
1
vote
1answer
71 views

Efficiency of scipy.sparse.linalg.expm_multiply with sparse vs unsparse vectors

From the package scipy.sparse.linalg in Python, calling expm_multiply(X, v) allows you to compute the vector ...
4
votes
0answers
56 views

Solving multiple linear regression in parallel

I am working on a problem where I need to solve approximately 500 Million Linear Regressions (OLS). What would be the most efficient way to do this (e.g. using GPU or a some framework that can do this ...
3
votes
3answers
232 views

Convolute a gaussian kernel with a large array of off-grid centroids without looping? (how to make "A Thousand (Gaussian) Points of Light" )

For a finite object size diffraction simulator, I need to generate arrays which are the sum of thousands of instances of a Gaussian (or other) 2D kernel at centroids that will not fall in any ...
1
vote
1answer
148 views

How to generate the convolution of f(x, y) with a parametric function g(t), x(t), y(t) in Python? (Something better than this brute-force sum)

The answer to Convolute a gaussian kernel with a large array of off-grid centroids without looping? (how to make "A Thousand (Gaussian) Points of Light" ) involves summing a 3D array over ...
1
vote
1answer
77 views

Numerical solution to the infinite well problem

I've used the following code to implement it ...
-1
votes
1answer
139 views

Using ODE to plot particle-motion with scipy.integrate.solve_ivp

My Problem: A positively charged particle (mass = 2 * 10-27 kg) is moving along the x-axis. It is travelling in a homogenous magnetic field such that the field axis in z-direction. The energy of the ...
0
votes
0answers
136 views

Do the projection (with Jacobian) and marginalisation (inversion of matrix and remove a row/column and reinversion) commute?

I try to check the equality or the inequality between 2 Fisher matrices. The goal is too see if the projection (with Jacobian) and marginalisation (inversion of matrix and remove a row/column and ...
-1
votes
1answer
164 views

Fitting using curve_fit of scipy in python gives totally different answer for 1/t and t

I was trying to fit some data to a single degree exponential decay function but a*exp(-x*t) and a*exp(-x/t) gives completely ...
0
votes
1answer
57 views

Trying to do a 2D random walk for a particle

I am trying to perform a two-dimensional random walk for a particle, but I am not getting the desired result. The plot produced is a linear plot, which obviously should not have been. Similar code for ...
0
votes
2answers
59 views

Passing in user inputs with mpirun

I am building a quantum circuit simulator using mpi4py. The simulator takes user inputs to build the initial system and quantum gates the system passes through. I can get the code to work if I do not ...
-2
votes
2answers
90 views

numerical solution for differential equation

I have these 3 equations and i want to solve them with numerical methods. so I am using scipy library but I don't know how to solve 3 equations together. R, g, sigma and density are constants. \begin{...
0
votes
0answers
73 views

How to distinguish primary hosts (stars) and orbiting satellites (planets) and tertiary bodies (moons) by their mass and trajectory?

I posted this question in the astronomy stackexchange. There are no responses, and it was suggested that I pose the question here. The "too long, didn't read" was taken from a comment, and ...
-1
votes
1answer
750 views

Generate 3D "matrix" with Pandas, based on comparing two dataframes [Python]

Good morning everyone. I am working with Python and Pandas. I have two DataFrames, of the following type: ...
0
votes
0answers
23 views

Why does this Non-Standard FDTD implementation lead to infinite increase in the magnitude of an EM pulse?

I have been working on a Particle-In-Cell Framework in Python and have noticed an issue where the magnitude of a EM pulse increasing infinitely as the simulation updates. Currently, I am using the Non-...
1
vote
0answers
41 views

Ising model in Python (Magnetization Scaling)

I am trying to implement the Ising Model in Python for Gibbs Distribution: $$\pi(x) = \frac{1}{Z(\beta)} e^{-\beta H(x)}$$ \begin{align*} p(x,y)&=r(x,y) \cdot \min \left( \frac{\pi(y)}{\pi(x)},1 \...
-1
votes
1answer
80 views

In a random walk simulation, how do I get the mean and standard deviation of how many times the walk returns to the origin?

So I'm simulating a 1-dimensional random walk, with 1000 walks that each take 1000 steps. How do I calculate the average number of times that a walker returns to the origin and then the standard ...
2
votes
1answer
197 views

How is the fuzzy logic calculated in scikit-fuzzy?

I am following this example from documentation of scikit-fuzzy library, but cannot figure out the math behind fuzzy rules there. Here is a short version of the ...
0
votes
0answers
42 views

Vector Form Using the Curl (Line Integral ) in Python

There is an example in Vector Calculus from Madsen & Tromba page 435 that states: Let $F=(xy^2,y+x)$.Integrate $(\nabla \times F)\cdot k$ over the region in the first quadrant bounded by the ...
0
votes
1answer
40 views

Question about scipy’s ivp solver

there is one thing I don’t understand. Is the tolerance to compute the step size updated at each timestep or fixed at all timestep. Also, when we look at the documentation and how the tolerance is ...
2
votes
1answer
225 views

Solving numerically the 1D Kuramoto-Sivashinsky Equation using spectral methods

Lately, I've been trying to solve numerically the 1D Kuramoto-Sivashinsky Equation using spectral methods. Let $\nu$ be the viscosity and $[0,L]$ the domain. The 1D equation is, $$ u_t + uu_x + u_{xx} ...
2
votes
3answers
170 views

Solving a PDE with 2 variables, with one variable whose derivative with respect to space is only known

I am trying to solve a PDE of the form $$\frac{\partial u}{\partial t} = D \frac{\partial^2u}{\partial x^2} + k\ \ \ (1)$$ where only $k$'s first derivative with respect to $x$ is known $$\frac{\...

1
2 3 4 5
15