Skip to main content
Share Your Experience: Take the 2024 Developer Survey

Questions tagged [scipy]

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

Filter by
Sorted by
Tagged with
4 votes
2 answers
10k views

Tikhonov regularization in the non-negative least square - NNLS (python:scipy)

I am working on a project that I need to add a regularization into the NNLS algorithm. Is there a way to add the Tikhonov regularization into the NNLS implementation of scipy [1]? [2] talks about it, ...
user3259573's user avatar
17 votes
1 answer
6k views

When is Newton-Krylov not an appropriate solver?

Recently I have been comparing different non-linear solvers from scipy and was particularly impressed with the Newton-Krylov example in the Scipy Cookbook in which they solve a second order ...
boyfarrell's user avatar
  • 5,409
16 votes
3 answers
17k views

What is the fastest way to compute all eigenvalues of a very big and sparse adjacency matrix in python?

I'm trying to figure out if there is a faster way to compute all the eigenvalues and eigenvectors of a very big and sparse adjacency matrix than using scipy.sparse.linalg.eigsh As far as I know, this ...
Noam Peled's user avatar
9 votes
1 answer
883 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
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
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
7 votes
2 answers
3k views

Numerical Integration with Convergence Factor with SciPy: Problem with Improper Integral

I would like to perform the numerical integration of an integral of the form $$ \int_{-\infty}^\infty e^{i \omega 0+} G(i \omega, \mathbf{v}) d \omega ,$$ or, using the symmetry $G(i\omega)^* = G(-i \...
RogueDodecahedron's user avatar
6 votes
3 answers
4k views

Computing numeric derivative via FFT - SciPy

I wrote the following code to compute the approximate derivative of a function using FFT: ...
Leonardo Araujo's user avatar
5 votes
1 answer
2k views

Solving for a set of coupled ODEs to get correct variable values

My question is about how I can solve a coupled system of ODE's, and print out the variables in a plot. I am solving for an q value and an e value, seen in this set of coupled ODE's below: $$ \begin{...
Nicole I.'s user avatar
5 votes
0 answers
551 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
5 votes
1 answer
188 views

Algorithm to factorize matrix whose many rows are already of upper triangular form?

I have a matrix whose many rows are already in the upper triangular form. $$\begin{bmatrix} x_{11} & x_{12} & x_{13} & x_{14} & x_{5} \\ 0 & x_{22} & x_{23} & x_{...
Akira's user avatar
  • 207
5 votes
0 answers
1k views

Symmetric sparse direct solvers in scipy

scipy.linalg.solve, in its newer versions, has a parameter assume_a that can be used to specify that the matrix $A$ is symmetric ...
Federico Poloni's user avatar
4 votes
3 answers
27k 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
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
2 votes
1 answer
894 views

Runge-Kutta fourth order method. Integrating backwards

I am using a Runge-Kutta fourth order method to solve numerically the usual equation of motion of a background scalar field in curved spacetime with a quartic potential: $\phi^{''}=-3\left(1+\frac{H^{...
user avatar
2 votes
3 answers
3k views

stop condition in scipy.integrate.ode for stiff system

I'm using Python scipy.integrate.ode, and I want to stop my integration at a certain condition. So I use the integrator "dopri5" and use the method "set_solout" to specify a function for my stop ...
Peter B's user avatar
  • 121
2 votes
1 answer
594 views

Computation time of eigenvalues with ARPACK depends on what?

My goal is to compute the k smallest eigenvalues of large symmetric sparse matrices. For this purpose I use python scipy's eigsh method in shift-invert mode which uses ARPACK. The matrices usually ...
Rena's user avatar
  • 21
2 votes
1 answer
3k views

Ways to solve $Ax=b$ for a sparse (banded) $A$ with updates

I want to solve the time-dependent Schrodinger Equation using the Crank-Nicolson scheme. I end up with the following matrix equation ...
Physicist's user avatar
  • 217
1 vote
1 answer
705 views

Eigenvalue problem for ordinary differential equation

I am trying to compute the natural frequency of a cantilevered beam. The Euler-Bernoulli equation reduces to the following problem : $$ v''''=\lambda v, \text{with }, v(0)=0, v'(0)=0, v'''(1)=0,v''(1)...
GMV871's user avatar
  • 33
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
1 vote
0 answers
103 views

Using absolute error as the cost function

This is related to my previous post Minimize distance between curves. I have a dataset with values of multiple curves. An example plot is shown below. I want to scale the curves (move up/down) so that ...
Natasha's user avatar
  • 421
1 vote
1 answer
1k views

scipy odeint: excess work done on this call and very sensitive to initial value

I am trying out odeint and received the error 'Excess work done on this call (perhaps wrong Dfun type).'. The values returned are also super sensitive to small ...
b-dog's user avatar
  • 13
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
0 votes
1 answer
3k views

How to define the derivative for Scipy.Optimize.Minimize

I am trying to use scipy.optimize.minimize to minimise a quadratic objective function: $f(x) =x^\top Q x$. As a start, I have successfully implemented this using the built-in Nelder-Mead Simplex ...
Zac's user avatar
  • 127
0 votes
2 answers
473 views

Why is this scipy.root code not converging?

I'm running a test problem to set up larger problems. Solving the simple unsteady heat equation via finite differences: $$ \frac{\partial T}{\partial t} = \alpha \frac{\partial^2T}{\partial x^2}$$ $\...
Klaus3's user avatar
  • 133
0 votes
2 answers
783 views

Is it possible to partition 2D data into bins such that each bin contains the same number of samples?

I am trying to sort data following a bivariate distribution into a numpy histogramdd, where each bin should contain the same number of data points (to the nearest whole sample). I expect that some ...
Zac's user avatar
  • 127
0 votes
1 answer
806 views

How to change the value of a variable at some point lying in the time interval of solver in solve_ivp

The following code solves a differential equation with scipy: ...
hinata exc's user avatar