Questions tagged [python]

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

164 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
1
vote
0answers
171 views

How to test for convergence (smoothness of Pareto front) in DEAP

In the DEAP algorithms (see documentation here), I notice that we need to specify the the number of generations (NGEN). I was advised that convergence has been achieved if the Pareto curve is smooth. ...
1
vote
0answers
1k views

Solving an integral equation in Python

I have to solve the following equation for $x(i), 0 \leq i \leq 1$: $$ y(i) = x(i)^{-a} \int_0^1 y(j)x(j) dj \left(\int_0^1 \mathcal A(j) x(j)^{1-a} dj\right)^{-1} \int_i^1 \left( \int_0^x x(j)^{1-a} ...
1
vote
0answers
112 views

Integral over reference element in $1$D FEM: how to map the quadrature points?

The following is related to a question a asked a few days back 1, but now I would like to focus on just one part of the problem. I have problems computing the integral over the reference element: $$ ...
1
vote
0answers
197 views

Lambdify error when sympy array contains number

This example is a dummy example, but it describes exactly whats goes on in my problem. As a result from some sympy calculation and manipulation i got two arrays ...
1
vote
0answers
157 views

vectorizating function integration scipy python

I need to implement the following in python: For a given discrete time series Zt (t=0 to T), find smallest t such that: $c\sum_{s=0}^t e^{[k(Zt-Zs)+m(t-s)]} >= \frac{p*}{1-p*} $ where c,k,m are ...
1
vote
0answers
303 views

How to obtain projections from sinogram in ART reconstruction technique?

I'm kind new in the Computed Tomography field and I'm trying to understand and implement ART technique. Said it, I started to read the book The Mathematics of Medical Imaging - A Beginners Guide by ...
1
vote
0answers
2k views

Finding eigenvectors and eigenvalues of large matrices in Python's numpy

I am running a PCA analysis on a data set using Python's (v2.7.10) NumPy. I validated that my program works by running the PCA analysis on a smaller dataset and then confirming that I get similar ...
1
vote
0answers
171 views

Numerical method to find stationary solution of an PDE in the phase space

I'm relatively new in numerical methods for PDEs, so I have a question about solving the following PDE numerically for $W(x,p)$ in the phase space: $$-p\frac{dW}{dx}+x\frac{dW}{dp}+\frac{d}{dx}\left(...
1
vote
0answers
65 views

Computing 3-term Connection Coefficients for Wavelets

I am trying to calculate the three-term connection coefficients $$ Λ_{l,m}^{d_1,d_2,d_3} = ∫_{-∞}^∞ φ^{(d_1)}(x) φ^{(d_2)}_l(x) φ^{(d_3)}_m(x) dx $$ for Daubechies wavelets numerically using Python. ...
1
vote
0answers
186 views

Generalized Hermite Function as eigenfunction of a differential operator

I'm going through this paper. The article defines function function $\phi_n^\mu(x)$ that is orthonormal on $L^2$ with measure $dm = dx$: \begin{equation} \phi^\mu_n =\left(\frac{\gamma_\mu(n)}{\...
1
vote
0answers
63 views

Solving a nonlinear problem with CDF

I'm trying to solve this problem: $\begin{cases} \partial_t E=-k\left([f(\rho)-i.\left[\delta+\frac{1}{2}a\left[\dfrac{\nabla^2_{\bot}}{4}+1-\rho^2\right]\right]]E - 2CP\right)\\ \partial_t P=-\...
1
vote
0answers
217 views

Inverse quadratic method only makes one iteration - python

I'm tryin' to implement this method with python3 but i don't solve the problem. This is my code: ...
1
vote
0answers
611 views

best package choice for visualizing agent based model simulations in python

This is a visualization/programming design problem. I am working on building a geospatial agent based model, meaning that there are multiple agents interacting within some particular spatial container....
1
vote
0answers
860 views

How to adjust scikit-learn FactorAnalysis() settings to get scores output similar to one from factanal() in R?

I'm new to factor analysis and I need to compute factor scores using Python. I have R code to compute scores and I want to ...
1
vote
0answers
102 views

Is this problem statement good for a GPU?

I am used to using GPU hardware for large scale matrix operations and vectorizing mathematical operations on a continuous space which has been discretized for numerical computation, but this is a ...
1
vote
0answers
12k views

Using scipy.quad to calculate difficult integral

When evaluating the integral below in python using scipy.quad I get the following warning: UserWarning: The maximum number of subdivisions (50) has been achieved. If increasing the limit yields no ...
1
vote
0answers
96 views

Principal Components Analysis Not Behaving as I Expect it to

I have a bunch of points in $\mathbb{R}^3$ that I would like to translate and rotate so that their center is at the origin and the variance along the $x$ and $y$ axes are maximal (greedy, and in that ...
1
vote
0answers
978 views

PageRank computation as the left principal eigenvector

I'm following the book here to compute PageRank: http://nlp.stanford.edu/IR-book/html/htmledition/markov-chains-1.html I built the transition matrix P as indicated in the book. Then I computed the ...
1
vote
0answers
82 views

Constraint solving over modular domains

I have a set of constraints over modular domains e.g. $\exists a \in A_i : x \equiv a \pmod{n_i}$ for all $i=0,\ldots,k$ The question is, does such an $x$ exist? I've been pointed to method of ...
0
votes
0answers
29 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 ...
0
votes
0answers
20 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 ...
0
votes
0answers
43 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-...
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 ...
0
votes
0answers
74 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 ...
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-...
0
votes
0answers
46 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
195 views

Pseudospectrum of non square Matrix in Python

I have a rectangular matrix $A \in \mathbb{R}^{m \times n}$ ...
0
votes
0answers
54 views

How to efficiently perform this 2D integral in Quadpy?

I need to integrate a function defined in 2Dims (z and radius r), for which I don't have an expression. I can just query the ...
0
votes
0answers
179 views

Numerical Range of a matrix in Python

In the mathematical field of linear algebra and convex analysis, the numerical range or field of values of a complex $n\times n$ matrix $A$ is the set $$W(A)=\left\{{\frac {{\mathbf {x}}^{*}A{\...
0
votes
1answer
227 views

Error using scipy.integrate.solve_ivp: index error: the index 0 is out of bounds for axis 0 with size 0

I am recently working on the code based on the stick-slip phenomenon in Python. It's the stick-slip oscillator (chapter 3.4) in https://www.sciencedirect.com/science/article/pii/S0888327020301205. And ...
0
votes
0answers
45 views

Newton-Raphson for estimating Weibull distribution does not converge

I've been trying to estimate the two-parameter (a,b) Weibull distribution (loc. param. = 0). $$f(t;a,b)=\frac{b}{a}\left(\frac{t}{a}\right)^{b-1}\exp(- \left(\frac{t}{a}\right)^b) $$ To find the ...
0
votes
0answers
103 views

1D Poisson equation and quadratic basis functions assembly

I'm solving the simple Poisson problem $$-u''(x)=1$$ in the interval $[0,1]$ with $u(0)=u(1)=0$. I discretised my domain as done here, i.e. with ...
0
votes
0answers
243 views

Numerov method for solving Schrödinger equation

I have just begun learning computer science to apply it to Physics and I am trying to write a code for solving Schrödinger's equation of the harmonic oscillator (setting $V=\frac{x^2}{2}$) in one ...
0
votes
0answers
251 views

similar function as fmincon in python?

I am trying to solve an optimization problem where I do not have the analytic form of the objective function. I am doing analysis by FEM to find a value for displacement in each iteration but I don't ...
0
votes
0answers
60 views

Calling User defined Matlab Functions in Python with Matlab.engine API

I am trying to combine Matlab and python scripts and figure out if I can achieve a better solution in terms of the solver-runtime. A very simple optimization problem is used just for now. But I got in ...
0
votes
0answers
71 views

Shape recognition of tangientially connected polygons using openCV

Lately, I have encountered the following problem, namely how to recognize the shapes of particular polygons. I have realized that quite straightforward to do so when the polygons are separated by ...
0
votes
0answers
25 views

petsc4py path error running PETSC program in python

I tried to run an example PETSC program in python. I used pyinstaller --onefile example.py to create a binary form and ...
0
votes
0answers
55 views

how can I plot specific iterations?

I have made this code for an explicit Euler method but I want to plot only the 0,1,25,50 iterations not all of them.How can I do it? ...
0
votes
0answers
127 views

Phase portrait of non-linear system of ode (Triple Galaxy System)

Context: Hello, I am an undergrad student of physics self-studying Python Programming. I am trying to find the value of H_lam for which limit cycles corresponding ...
0
votes
0answers
80 views

Python evaluating a second order ODE with RK4

Pasted below is my python code. It is a 4th order runge kutta that evaluates the 2nd order ode: y'' +4y'+2y=0 with initial conditions y(0)=1, y'(0)=3. I need help fixing it. When I run my code, my ...
0
votes
0answers
22 views

3d surface image for given datasets

I have some data that looks like as follows x-cor y-cor z-cor 0.02 0.0251 0.02 0.01 0.0257 0.02 0.014 0.02 0.03 0.023 0.003 0.05 0.013 0.002 0.77 .................... .................... ...
0
votes
0answers
28 views

Negative binomial expansion of general symbolic polynomial

Using Sympy, I would like to compute the negative binomial expansion of a general symbolic polynomial, e.g., $(x_1 + x_2 + x_3 + 4 x_4)^{-1}$. I understand that I can go by recursively partitioning ...
0
votes
0answers
341 views

How to take convolution of two arrays in Python by using NumPy?

Generally, we know that if we have this relation between Fourier transforms of three functions in frequency domain as: $$\mathfrak{F}\{\mathsf{P}(t)\} = \mathfrak{F}\{\mathsf{Z}(t)\}\mathfrak{F}\{\...
0
votes
0answers
29 views

Set of integrators do not consistently solve an equation in Python

I must solve the following second order differential equation: $\delta \phi^{''}_{\mathbf{k}}+(3-\epsilon)\delta \phi^{'}_{\mathbf{k}}+\left(\frac{k^2}{a^2 H^2}+\frac{V_{,\phi\phi}}{H^2}-6\epsilon +4\...
0
votes
0answers
178 views

Plotting a Magnetic Field in Spherical Coordinates in Python

I am modeling a Helmholtz Coil as two dipoles from far away and I want to plot the magnetic field. $$\mathbf{B}(\mathbf{r}) = \frac{\mu_0 |\mathbf{m}|}{4\pi r^3}\left(2\cos\theta\,\hat{\mathbf{r}} + \...
0
votes
0answers
144 views

scipy's solve_ivp returns erroneous results for a stiff differential equation

I'm using scipy's solve_ivp for solving a stiff differential equation. I'm using method BDF for solving the same. I have already used MATLAB's ode23s and I'm getting correct results in MATLAB. However,...
0
votes
0answers
151 views

A parallelized GMRES solver?

My application calls for solving a dense, 40,000 x 40,000, ill-conditioned linear system. The native SciPy GMRES solver with preconditioning has worked well for my application and solving a single ...
0
votes
0answers
34 views

Comparing custom linear regression solver to SciPy equivalent in Python

From a given data set, I set out to complete a task which is below Fit the data of the previous exercise to fit Eq. (8.18) using the SciPy function ...
0
votes
0answers
63 views

Scipy.integrate.odeint is returning curves with almost the same frequency for different damping ratios, shouldn't they be different?

I am trying to solve the ODE for a harmonic oscillator using Scipy's odeint solver for different dampening factors. I'm using the following code, based off of this example: ...
0
votes
0answers
473 views

Solving nonlinear pendulum using Runge-Kutta 4 for smaller steps

I am trying to solve nonlinear pendulum using 4th order Runge-Kutta method for limits between a=0.0 to b=110 seconds and simulated the results to observe the pendulum movement. But when I increase the ...