Questions tagged [scipy]

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

Filter by
Sorted by
Tagged with
0
votes
1answer
42 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 ...
1
vote
1answer
46 views

Numerical integration problem: IntegrationWarning The integral is probably divergent, or slowly convergent

I am trying to get the numerical integration of a function using scipy's integrate.quad as follows. $$ \begin{equation} G (\alpha) = \frac{4\alpha}{\pi}\int_0^{\...
2
votes
0answers
25 views

Scaling tensor approximation by symmetric tensor decomposition with SciPy's L-BFGS-B

I am trying to approximate a symmetric tensor of which the values are in the range of [1e-7,1e-4], by a symmetric tensor decomposition of lower rank. For this I am using the L-BFGS-B method in SciPy's ...
0
votes
1answer
27 views

Odeint error for nonlineal differential equations

I receive the following error when I run the code. ODEintWarning: Excess work done on this call (perhaps wrong Dfun type). Run with full_output = 1 to get quantitative information. warnings.warn(...
2
votes
2answers
182 views

Python scipy eigh(Arpack) giving wrong eigenvalues for generalized eigenvalue problem

I am trying to solve a generalized eigenvalue problem using Arpack, right now the code is using LAPACK but that's too slow, we only need a few eigenvalues and the matrices are sparse so using Arpack ...
3
votes
1answer
135 views

How to get a more accurate cancelation

I shall try to get to the point, so let me know if there is something left and you need more details. I am solving a couple of equations that are not coupled explicitly, but their corresponding ...
0
votes
0answers
83 views

The inverse of the numpy.gradient function

The numpy.gradient function is computed using second order accurate central differences in the interior points and either first or second order accurate one-sides (forward or backwards) differences at ...
1
vote
1answer
72 views

DOP853 integration method is missing (SciPy)

I was checking some integration methods provided by SciPy, in which the DOP853 should be included according to the webpage (https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate....
0
votes
0answers
26 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\...
2
votes
0answers
56 views

Determine the anti-derivative of 2D vector field

I have data on a (x,y) grid with scalar values (time) at each point. I have used the numpy gradient function and linear interpolation to determine the gradient vector Velocity (Vx,Vy) at each point (...
0
votes
1answer
55 views

How to use cumtrapz correctly?

I have tried to do a trapeze integration with f(x)=x^2, where I know how the antiderivative looks like, so F(x) = (1/3)x^3 Here's my code, just like I tried: ...
0
votes
0answers
60 views

Applying the result of Cuthill-McKee in SciPy (followup)

This is a followup to Applying the result of Cuthill-McKee in SciPy , where I'm not sure the answer given is correct. It's also 4 years old, so I'm trying a new question. The question is still ...
2
votes
0answers
37 views

Non-negative Least Squares to perform Inverse Laplace with weights

I'm trying to perform the inverse Laplace transform of a (noisy) dataset $y_i$ using Tikhonov regularization: $$\min \sum_{i=1}^{N} \left(\int_0^\infty e^{-s_i t} f(t) \, dt - y_i \right)^2 - \lambda^...
0
votes
0answers
42 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
77 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 ...
1
vote
1answer
161 views

Is LAPACK behind the cutting edge of dense linear algebra?

I have been digging into some numerical linear algebra lately, and reading in particular about how LAPACK solves symmetric eigenvalue problems. I noticed that the ...
0
votes
0answers
29 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 ...
2
votes
1answer
68 views

Functions from Scipy, Blas, or Lapack that compute only upper triangular matrix

My goal is to transform a matrix into upper triangular form in Python. I know the function scipy.linalg.lu will do LU decomposition and get both upper and lower ...
3
votes
1answer
169 views

Why is 'scipy.sparse.linalg.spilu' less efficient than 'scipy.linalg.lu' for sparse matrix?

I have a matrix B which is sparse and try to utilize a function scipy.sparse.linalg.spilu specialized for sparse matrix to ...
5
votes
1answer
152 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_{...
3
votes
1answer
111 views

Computing numeric derivative via FFT - SciPy

I wrote the following code to compute the approximate derivative of a function using FFT: ...
3
votes
1answer
59 views

Fast nonzero indices per row/column for (sparse) 2D numpy array

I am looking for the fastest way to obtain a list of the nonzero indices of a 2D array per row and per column. The following is a working piece of code: ...
0
votes
0answers
10 views

How to optimize linear programming subproblems with respect to global constraints?

I have an optimization problem where I have several categories and for each category $j$ I have entries $i = 1....m$, I wish to assign some value $x_{ij}$ for each entry of each category but: I need ...
0
votes
0answers
22 views

How to plot a function for multiple values of a parameter in the same set of axes in Python?

I'm currently trying to plot a graph wich describes a photoionization cross section as a function of incident photon energy for optical transition in a semiconductor for different values of the $\...
1
vote
1answer
45 views

How do I get scipy.minimize to terminate below a certain loss threshold?

I was looking at the scipy.minimize documentation to see if I could find a way to terminate optimization when the loss gets below some cut-off, and I couldn't see ...
5
votes
0answers
102 views

How to numerically evaluate this double Integral?

I want to evaluate the following integral: $$\int_{0}^{60} \ \left(\int_{0}^{2z} 0.5\cdot t \left(\mathrm{erf}(t-a) -1 \right)J_{0}(qt)\mathrm{d}t \right)^2 \mathrm{exp}\left(-\frac{(z-a)^2}{2s^2}\...
0
votes
1answer
55 views

Solving an ODE using odeint in Python and continuing the integration

The following relates to the linked question: Scattering of waves in a symmetrical potential (using python) I have attempted to solve the problem for $U(r)$ using ...
0
votes
1answer
32 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: ...
0
votes
1answer
108 views

solve_ivp - Overflow encountered in double_scalars

I'm modeling an electron that orbits the nucleus. Of course, charged particles radiate away there energy so it'll crash into the nucleus. My approach has been to to evaluate the coulomb force and add ...
2
votes
1answer
35 views

How to implement Simpson's rule for double integral (without numeric limits of first integral)

I want to use Simpson's rule to evaluate the following double integral: $$\int_{a}^{b}\left|\int_{0}^{z}x\cdot \mathrm{erf}(x-10)\cdot J_{0}(x) \mathrm{dx}\right|^{2}\exp(-0.5*(z-40)^2)\mathrm{dz} $$ ...
0
votes
0answers
35 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: ...
3
votes
1answer
63 views

Plotting optimum as a function of parameter in the objective

I am trying to minimize a 2d function using scipy.optimize. Specifically I want to plot the minimum value of the function fun as a function of the parameter wjk. The problem is that I cannot pass wjk ...
1
vote
1answer
102 views

Translating the Euler code in scipy's solve_ivp

My code is based on the similarity transformation X=VZ.I simulate the model for transformed equations involving Z by replacing ...
0
votes
0answers
23 views

Can Scipy.optimize take a user-defined objective function that contains an ML model?

I have an optimization task that requires me to choose the optimal combinations of parameters, according to the prediction of a random forest model. My main obstacle is that scipy.optimize always ...
-1
votes
1answer
57 views

Plot of a function involving an integral and value changing parameters [closed]

I'm trying to plot the cross section with respect to the photon energy $h\nu$ but for $\gamma = 1.0, 1.2, 2.0 $ in the same axes $\sigma = \left[\left(\frac{\xi_{eff}}{\xi_{0}}\right)^2 \frac{n_r}{\...
5
votes
1answer
203 views

How to know which LAPACK's function is used by Scipy's eig function?

As far as I understood, scipy.linalg.eig use wrappers from scipy.lapack to compute the eigenvalues and eigenvectors of a matrix. ...
5
votes
1answer
87 views

How do I globally change the precision of a piece of code in Python to debug it?

I am solving a system of non-linear equations using the Newton-Raphson method in Python. This involves using the solve(Ax,b) function (...
0
votes
1answer
128 views

Solving differential equation in Python with discretized variable coefficients

I am trying to solve a differential equation with discretized variable coefficients which are calculated from a time serie. In this case the Runge-Kutta step size is fixed by the frequency in the time ...
2
votes
1answer
70 views

How to set up a time-dependant matrix for an ODE to be solved using python?

I want to solve a problem numerically in python like this: $$ y(t)' = \mathbf{M}(t)y ,\\ y(0) = (1,0,0,0 ...) $$ where $y$ is an $n$-dimensional vector and $\mathbf{M}(t)$ is a time-dependant $n \...
5
votes
0answers
201 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 ...
0
votes
0answers
21 views

How to handle system of chemical reactions for a batch reactor SciPy solver

I have a system of chemical reactions where the rate equations represent a batch reactor model. The model is a system of ODEs which is solved with the SciPy ...
3
votes
1answer
399 views

Numerical derivative in python

I am trying to take the numerical derivative of a dataset. My first attempt was to use the gradient function from numpy but in that case the graph of the derivative ...
1
vote
1answer
177 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^{...
3
votes
1answer
132 views

Scipy Spline Interpolation Parameter

Documentation in scipy.interpolate (found at https://docs.scipy.org/doc/scipy/reference/tutorial/interpolate.html) states: "The parameter variable is given with the keyword argument, u, which ...
3
votes
1answer
96 views

Conjugate Gradient for singular 2D poisson finite element with Neumann Boundary Conditions

Heavily edited question after I realised partly what the problem was I have programmed a simple 2D square finite element solution to the Poisson equation $-\Delta u = f$ The source function ...
5
votes
3answers
180 views

Maximize a function of an orthogonal matrix

I'm trying to write up a small code that, given a set of normal vibrational modes for a molecule, will convert them to localized vibrational modes. To do this I'm following the procedure from J. Chem. ...
6
votes
2answers
1k views

Is there an efficient way to form this block matrix with numpy or scipy?

Is there an efficient way to form this block matrix with numpy or scipy? $$ \left[ \begin{array}{cccc} \mathbf{B} & \mathbf{0} & \cdots & \mathbf{0}\\ \mathbf{AB} & \mathbf{B} & \...
1
vote
1answer
185 views

Preconditionning for solving a non-linear system of equations with least squares

I am trying to solve a large system of non-linear equations (about a few hundred equations and variable but with less variable than equations). Given that the system is really sparse and large I am ...
3
votes
1answer
251 views

Get the roots of a Hermite interpolating polynomial

I am using Python 3.7 to write a program that requires me to calculate the root of the Hermite interpolating polynomial, given two points $\epsilon_0$, $\epsilon_1$, the function ($d(\epsilon_0)$,$d(\...
4
votes
2answers
2k views

Numerical evaluation of a Gaussian Integral in Python?

Goal I'm trying to write code to compute the normalized Gaussian in the following, $$ \begin{equation} \int_{-\infty}^{\infty} \frac{1}{ \sigma \sqrt{2 \pi}} \exp\bigg( - \frac{(x - \mu)^{2}}{2 \...