Skip to main content

Questions tagged [scipy]

SciPy is a Python-based ecosystem of open-source software for mathematics, science, and engineering.

Filter by
Sorted by
Tagged with
1 vote
0 answers
81 views

Convert scipy integration with one step to matlab integration

Scipy integration allows us to do ode integration one adaptive timestep at a time and do something to it. However, matlab ode needs us to specify a timespan , and determine the adaptive timestep ...
diff's user avatar
  • 121
1 vote
0 answers
213 views

vectorizing optimization or root finding [closed]

I need to find the roots of a function. I am currently using scipy.optimize.fsolve ...
dayum's user avatar
  • 163
3 votes
1 answer
2k views

integral including a vector

I need to calculate the integral of this function def f(z): return ((1-2*z)*np.exp(-d/z))/(((1-z)**(2+d))*(z**(2-d))) Here d is a constant. I am using this ...
dayum's user avatar
  • 163
1 vote
0 answers
349 views

Vectorize function integration

I need to implement the following in python: For a given discrete time series $Z_t$ ($t={0...T}$), find the smallest $t$ such that: $$c\sum_{s=0}^t e^{[k(Z_t-Z_s)+m(t-s)]} \geq \frac{p^*}{1-p^*} $$ ...
dayum's user avatar
  • 163
7 votes
1 answer
956 views

Why does LSODA fail to integrate the logistic function?

I'm comparing some of the different ODE integrators in scipy.integrate.ode on solving the logistic function: $$x(t) = \frac{1}{1+e^{-rt}}$$ $$\dot{x} = rx(1-x)$$ ...
joh's user avatar
  • 173
0 votes
1 answer
1k views

Use of scipy sparse in ode solver

I am trying to solve a differential equation system $$x´=Ax\quad \text{with } x(0) = f(x)$$ in Python, where $A$ indeed is a complex sparse matrix. For now i have been solving the system using the ...
Amund Jenssen's user avatar
9 votes
1 answer
890 views

Matrix Balancing Algorithm

I have been writing a control system toolbox from scratch and purely in Python3 (shameless plug : harold ). From my past research, I have always complaints about ...
percusse's user avatar
  • 393
3 votes
0 answers
401 views

How to reuse permutation-orderings within scipy's SuperLU-wrapper?

i'm solving sparse linear equations within scipy 0.18 which internally resorts to SuperLU (after umfpack got removed due to license-issues). Current, i'm doing a complete re-factorization in each ...
sascha's user avatar
  • 131
3 votes
2 answers
4k views

Applying the result of Cuthill-McKee in SciPy

I have applied SciPy's implementation of the Cuthill-McKee algorithm to a $48 \times 48$ sparse non-symmetric matrix in Compressed Sparse Row (CSR) format and the output is an array of length $48$ ...
Johan Falkenjack's user avatar
0 votes
2 answers
284 views

Fast Python implementation of short-range interacting particles under Metroplis algorithm

Can anyone write a Python implementation of a set of particles interacting in 2D according to a short-range particle-particle force and evolving in time under a Metropolis algorithm, which randomly ...
user avatar
3 votes
0 answers
697 views

Gradients of non-uniformly sampled data in 3D space

I have measurements of magnetic field on a 3d grid. My measurements are distributed on four x-y planes similar to what is shown in the image below. The measurements roughly follow a Cartesian grid but ...
jensv's user avatar
  • 133
1 vote
0 answers
1k views

linearly interpolate and determine gradients for data on non-uniform grid

I have measurements of a quantity on a 3d grid. My measurements are distributed on four x-y planes similar to what is shown in the image below. The measurements roughly follow a Cartesian grid but ...
jensv's user avatar
  • 133
8 votes
3 answers
4k views

What does Python offer for distributed/parallel/GPU computing?

Using the SciPy/NumPy libraries, Python is a pretty cool and performing platform for scientific computing. I just wonder: When I have to go parallel (multi-thread, multi-core, multi-node, gpu), what ...
Michael's user avatar
  • 1,463
1 vote
1 answer
806 views

Preconditioning of two step iteration for dense matrices

I would like to solve a dense linear system the form in python $$ L\left(\boldsymbol{x}\right):=\left[\gamma^+\left[\boldsymbol{A}+\frac{1}{2}\boldsymbol{B}^{-1}\right] +\gamma^-\left[\boldsymbol{A}-\...
sebastian_g's user avatar
5 votes
1 answer
5k views

Solve rate equations with different reaction orders using SciPy ode

The image below illustrates the kinetic scheme I am trying to model. My first example focuses on the conversion of the wood-oil to non-volatiles and volatiles. The rate equations are as follows: $$ ...
wigging's user avatar
  • 325
1 vote
0 answers
191 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)}{\...
Константин Высоцкий's user avatar
0 votes
2 answers
520 views

Repeated 1d minimization with similar parameters (scipy)

I have a function f(x,k1,k2) and I am trying to minimize it over x for different values of ...
user1830663's user avatar
2 votes
2 answers
439 views

Why do Newton-Krylov iterations stagnate in this problem? [closed]

Consider this integro-differential heat equation taken from SciPy documentation page: $ \nabla^2 P = \alpha \left(\iint_\Omega \cosh(P)dx dy \right)^2 $ which was found in this question. In the ...
faleichik's user avatar
  • 1,832
2 votes
1 answer
176 views

Methods for solving $x'=Ax+b$ for small, sparse, singular $A$

I am in the process of building a robotics physics engine. I have been using the Linear ODE $x' = Ax + b$ for the core of my physics integration, but have never found a really good solution method for ...
computer-whisperer's user avatar
2 votes
1 answer
813 views

(numpy/scipy) Build a random vector given mean vector and covariance matrix

After running several calculations with numpy, I end with the mean vector and covariance matrix for a state vector. Is there a way with numpy or scipy to sample a random vector around this mean and ...
computer-whisperer's user avatar
7 votes
4 answers
34k views

Plot integral function with scipy and matplotlib

I want to plot a numerical integral function of some function $f$ using scipy and matplotlib. How can I do this? I tried the ...
student's user avatar
  • 231
1 vote
0 answers
196 views

Is it worth switching to timesteppers provided by PETSc if I can't write down a Jacobian for my problem? Case study with "the amoeba" toy problem

I am considering using petsc4py instead of scipy.integrate.odeint (which is a wrapper for Fortran solvers) for a problem ...
bzm3r's user avatar
  • 659
4 votes
4 answers
11k views

LCM builtin in Python / Numpy

I can write a function to find LCM (lowest common multiple) of an array of integers, but I thought it must have been implemented in numpy or scipy and was expecting something like ...
Pagol's user avatar
  • 143
8 votes
1 answer
2k views

Numerical solution of Geodesic differential equations with Python

I have made a solver based on the SymPy.diffgeom library, where I use Scipy.Integrate to solve the following system of second order differential equations : \begin{align} u'' &+ \Gamma^0_{00}(u')...
imranal's user avatar
  • 425
0 votes
1 answer
255 views

Solve a pair of coupled nonlinear equations within certain limits

This answer to this question works only for situations in which the desired solution to the coupled functions is not restricted to a certain range. But what if, for example, we wanted a solution such ...
abcd's user avatar
  • 107
3 votes
1 answer
1k views

Numerical integration with singularities

I need to compute some integrals numerically. The integrand is this: $$f(x,y) = \left ( \sum_{mn=-j}^{j}A(m,n)\dfrac{\tan^{2j+m+n}(x/2)}{(1+\tan^2(x/2))^{2j}}e^{iy(n-m)} \right )^{N}$$ Note: sums ...
Victor Buendía's user avatar
3 votes
1 answer
133 views

Use scipy to get any vertex of polytope

I need to get just a random vertex of a polytope. Any will do. The only way I can do this now is to pick a random function (say 0s) to maximize with scipy.optimize.linprog. However, this is wasteful, ...
Elliot Gorokhovsky's user avatar
3 votes
2 answers
3k views

Scipy OdeInt solver with Neumann boundary conditions

I'm using scipy.odeint to solve Fisher-Kolmogorov equation: \begin{equation} u_t = u_{xx}+u(1-u) \end{equation} The code can be found here. From Ablowitz and ...
ilciavo's user avatar
  • 289
9 votes
1 answer
454 views

Forcing an ODE solver to preserve the norm

I have an ODE of the form $$ \frac{dy}{dt} = -i H y \enspace .$$ where $y$ is a complex vector and $H$ is a time dependent Hermitian matrix. The norm of the solution $y(t)$ at any point in time ...
Krastanov's user avatar
  • 193
7 votes
2 answers
6k views

Solve non-linear set of three equations using scipy

I need to solve a non-linear set of three equations using scipy. However, I do not have any clue on which algorithm is suitable for my problem from a mathematical point of view (stability, convergence ...
albert's user avatar
  • 203
1 vote
0 answers
553 views

scipy.integrate.ode ignores boundary conditions [closed]

I am trying to solve the 1-dimensional diffusion problem numerically using method of lines: $$ \frac{\partial c}{\partial t} =D \frac{\partial^2 c}{\partial z^2},$$ where the right hand side is ...
user3053332's user avatar
13 votes
1 answer
2k views

Can an approximated Jacobian with finite differences cause instability in the Newton method?

I have implemented a backward-Euler solver in python 3 (using numpy). For my own convenience and as an exercise, I also wrote a small function that computes a finite difference approximation of the ...
Stephen Bosch's user avatar
3 votes
1 answer
649 views

General heuristics for making a choice "dopri5", and "lsoda"?

With scipy, I have the choice of using "lsoda": Real-valued Variable-coefficient Ordinary Differential Equation solver, with fixed-leading-coefficient ...
bzm3r's user avatar
  • 659
0 votes
1 answer
3k views

`scipy`: what does `scipy.integrate.odeint`'s Repeated convergence failures (perhaps bad Jacobian or tolerances)." error mean?

What does the following scipy.integrate.odeint error mean numerically? ...
bzm3r's user avatar
  • 659
5 votes
0 answers
556 views

Iteratively finding both left and right eigenvectors for non-symmetric complex matrix

I have a complex, non-Hermitian matrix $\mathbf{A}$, for which I need to find a few eigenvalues and eigenvectors in the generalised eigenvalue problem: $$\mathbf{A}\cdot \mathbf{x} = \lambda \mathbf{...
DaveP's user avatar
  • 161
0 votes
1 answer
436 views

Scipy min warning meanings?

What does "Desired error not necessarily achieved due to precision loss" mean in the context of the scipy_fmin methods? I can't ...
user2574476's user avatar
5 votes
1 answer
398 views

Quantify integration error of scipy ode / ODEPACK

I am trying to integrate a 2nd order ODE with potential several singularities using the lsoda solver wrapped in scipy.integrate.ode(). I would like to put an error bar on the solution or at least ...
jensv's user avatar
  • 133
7 votes
4 answers
9k views

Algorithm for high quality 1/f noise?

How can I generate arbitrarily high quality $1/f$ noise, for use in a model? My model involves a lot of feedback, over a large number of iterations, with a very high bandwidth, so I'd like the $1/f$ ...
Seth's user avatar
  • 173
0 votes
1 answer
524 views

Unconstrained minimization of unbounded function with SciPy

It seems that scipy.minimize can find the minimum of an unbounded function. ...
Paul G. Constantine's user avatar
4 votes
0 answers
91 views

Large residual when integrating 2nd order ode close to singularity with SciPy ode / ODEPACK

I am trying to integrate a 2nd order ODE with a singularity at close to the initial condition. Why do I get large residuals when I plug-in the result of my integration back into the ODE? The equation ...
jensv's user avatar
  • 133
0 votes
1 answer
1k views

What Python libraries do I need to do computational physics? [closed]

I need to install Python to do some undergraduate level computational physics (course, not research). What library do I need? Scipy only?
velut luna's user avatar
12 votes
5 answers
13k views

Dynamically ending ODE integration in SciPy

I have a light ray moving through space-time, i.e. a curve in $\mathbb{R}^4$, parametrized by some variable λ. The exact trajectory, i.e. the coordinate functions $x^μ(λ)$ of the curve are given by ...
balu's user avatar
  • 243
8 votes
1 answer
5k views

Numerical evaluation of an elliptic integral in python

Goal: I need to evaluate numerically an integral of the following form: $$ \int_0^\infty \frac{dx}{(a^2+x)\sqrt{(a^2+x)(b^2+x)(c^2+x)}} $$ where $a,b,c \in \mathbb{R}$ are in the interval $(1,1000)$....
Eric Kightley's user avatar
4 votes
3 answers
28k views

scipy odeint - Excess work done on this call

I'm newbie both in calculus and Python/Scipy so I apologize if this question is too dumb. I'm trying to model flow between two pressure vessels. Let's say we have two points and a link between them ...
Farid83's user avatar
  • 143
1 vote
0 answers
192 views

How to compute frank copula and its derivative accurately?

I need to fit a model using MLE with Frank copula by linking two discrete univate distribution function $u = F(x)$ and $v = F(y)$ together, and the joint distribution function is $$ \Phi(x,y) = C(F(x)...
wh0's user avatar
  • 183
1 vote
1 answer
125 views

Possible to reduce effort needed to solve non-linear ODEs by taking some coefficients/parameters as constant over small time intervals?

So far, I have been using scipy.integrate.odeint as my "workhorse" ODE solver. My current problem requires that I solve a large system (up to ~5000) ODEs. Here's ...
bzm3r's user avatar
  • 659
1 vote
2 answers
4k views

scipy.integrate.odeint: how can odeint access a parameter set that is evolving independently of it?

I might have some non-linear ODEs that are being solved by scipy.integrate.odeint. However, a parameter at each time step might have to be updated by using a non-DE ...
bzm3r's user avatar
  • 659
2 votes
2 answers
2k views

How best to use scipy.integrate's ODE solvers when state is not naturally stored as a vector?

I have a large system of ODEs. For various reasons, it is natural to store the values of the dependent variables in a multidimensional array. For example, these values might represent the solution ...
bzm3r's user avatar
  • 659
0 votes
1 answer
1k views

How can I use Scipy to fit data generated from a C++ model?

I currently have a functioning and blazing fast model written in C++ and CUDA. However, I'd like to use Scipy.minimize to fit the model to some experimental data. I was hoping it would be easy, but ...
Hair of Slytherin's user avatar
2 votes
1 answer
343 views

Speedier alternative to “skimage.morphology._pnpoly import points_inside_poly”?

I am using scikit-image's points_inside_poly function, and in my code I am calling it enough times that it takes up about 50% of ...
bzm3r's user avatar
  • 659