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
1 answer
31 views

solve_ivp method=ODE23 time step not decreasing in order

My time step with the function scipy.integrate.solve_ivp is not decreasing in t_span fluctuating (reaching values below or ...
louis gouders's user avatar
1 vote
1 answer
111 views

Different Results for Double Pendulum

In this study, (Hidden Fractals in the Dynamics of the Compound Double Pendulum) the authors provide various fliptime fractals (of a double pendulum) for different length combinations. However, when I ...
MaximeJaccon's user avatar
0 votes
2 answers
58 views

scipy exp model fitting: prevent coefficients blowup

I'm trying to fit a few X-Y points that look like exponential. I used the following scipy code: ...
mastican's user avatar
2 votes
0 answers
62 views

Hyperbolic integral of the second kind

The elliptic integral of the second kind is given by $$ E(t,m) = \int_{0}^t \sqrt{1-m \sin(s)^2} \operatorname{ds} $$ and there is for instance a scipy function ellipeinc that computes it. The ...
Strichcoder's user avatar
0 votes
0 answers
27 views

using scipy.sparse.linalg.eigsh for degenerate states in Bose Hubbard model

I am currently writing a code for the Bose-Hubbard model, and I am calculating the ground states and single-particle density matrix for different values of U and J. As U=0, one would see how the ...
Lorenzo Carfora's user avatar
0 votes
2 answers
101 views

BFGS Constrained Optimization Failure Due to Precision Loss

I am trying to optimize the following objective function according to some constraints. However, the optimization fails at the first iteration with the message that the desired error was not ...
user47212's user avatar
1 vote
2 answers
411 views

optimizing piecewise linear objective functions (perhaps non convex) with equality constraints

When I do my project, I need to optimize piecewise linear objective functions (perhaps non convex) with equality constraints. The piecewise linear objective function may be not convex like this in the ...
Yiyuan Chen's user avatar
0 votes
0 answers
89 views

How to minimize a numerical integration in python?

I need some help to minimize a numerical integration. It's about a classical problem in physics (hydrogen atom). It can be solved analytically but I need to solve it numerically in Python. We have an ...
Rubens Filho's user avatar
0 votes
0 answers
59 views

Singular Matrix Error in Incomplete LU Decomposition

I’m currently working on solving the following PDE: $$\begin{equation} -(\mu_x \frac{\partial^2 u}{\partial x^2} + \mu_y \frac{\partial^2 u}{\partial y^2}) = f(x, y)\end{equation}$$ Where a right hand ...
blov's user avatar
  • 43
5 votes
2 answers
2k views

What algorithm(s) do numpy and scipy use to calculate matrix inverses?

I am solving differential equations that require inverting dense square matrices, and I wanted to know what algorithm(s) do numpy and scipy use to calculate matrix inverses?
kamy rez's user avatar
2 votes
1 answer
65 views

Numerical calculation of Lyapunov exponents using SciPy's built-in solve_ivp

I have previously successfully implemented the QR decomposition method in MATLAB to calculate Lyapunov exponents for Lorenz equations. See here. This method integrates the stacked system, i.e. the ...
Axel Wang's user avatar
  • 197
0 votes
1 answer
63 views

How to use a custom OdeSolver in Scipy's solve_ivp

In Scipy's solve_ivp documentation, we see the method argument can be either a string or a user-defined ...
Axel Wang's user avatar
  • 197
5 votes
2 answers
460 views

Number of function calls and jacobian calls in scipy.root

Just as an exercise, I am numerically solving the following system of equations: $$ \begin{equation} \begin{cases} x^2 + y^2 = 32 \\ 3x + 7y = 15 \end{cases} \end{equation} $$ ...
Tarik's user avatar
  • 173
0 votes
0 answers
112 views

Solving system of ODEs, where time derivative approaches infinity due top initial condition

I am trying to solve a problem in python using scipy's solve_ivp. The system of ODEs I am trying to solve is for coupled where I am solving for two time-dependent ...
HWIK's user avatar
  • 23
2 votes
1 answer
124 views

Weights for equidistant samples in power law fitting

I am working on fitting analytical curves to experimental data obtained in real viscoelastic tests (in fact, static creep tests). The setting of the problem is: the experimental data I have is a set ...
ren1's user avatar
  • 23
2 votes
1 answer
152 views

2D integrals in Python with specified points of interest

Note: This is my first question on stackexchange; please tell me if I'm doing something incorrectly. I am trying to calculate a series of a 2D integrals in Python with an integrand that has several ...
Feathers's user avatar
1 vote
0 answers
207 views

Using solve_ivp for a PDE: how to handle multiple time-dependent variables?

I am trying to build a Python code that solves a set of coupled differential equations which will be spatially discretized by the method of lines advancing in time. I am planning to use ...
Ziad Nasef's user avatar
2 votes
2 answers
331 views

Solving IVP backward in time via python

I'm having difficulty solving an initial value problem (IVP) in Python backwards in time. The code is at the end of this post. First, please let me state my simplified problem. The forward IVP is ...
JesseJC's user avatar
  • 21
0 votes
0 answers
25 views

Matching the limits of integration with the proper variables in a complicated case when using scipy.integrate.nquad

I need to integrate expressions containing powers of the function: ...
ale victor's user avatar
6 votes
1 answer
276 views

Accelerating the computation of scipy.sparse.linalg.expm_multiply

I have a tridiagonal antiHermitian matrix ($-i*Hami*t$) with nonzero elements only along the upper diagonal and lower diagonal, and the goal is to know the action of exponential of such matrix on a ...
code437's user avatar
  • 63
1 vote
1 answer
115 views

Possible bug with scipy.optimize SHGO sobol: TypeError: <lambda>() takes 1 positional argument but 3 were given

I have been trying to perform some global optimization with SciPy optimizer SHGO and I've had issues with the sampling method 'sobol'. Specifically, I get an error ...
Sasche's user avatar
  • 31
2 votes
2 answers
95 views

How do I evaluate the numerical solution at a point that isn't on the mesh

I'm trying to code a fixed-point method to solve the following system using scipy.integrate $$ u_{n+1}(s)=\int_0^TK_\lambda(t,s)\left(\lambda u_n(t)+\sigma(t)+f(t, ...
tareqath's user avatar
0 votes
2 answers
59 views

How to program the convergence of a sequence of systems of integral equations using Scipy

I'm trying to solve the problem where $u_n$ and $v_n$ are sequences that converge to the solution $u$ and $v$ and $\lambda$, $\sigma$, $f$ and $g$ and K_lambda are all given. I thought of using the ...
tareqath's user avatar
-1 votes
1 answer
139 views

Solving Transcendental equation involving special functions becoming nightmare any one can help?

Simply i want to solve for schrodinger equation for finite potential well problems in spherical coordinates. For case in which l=0 . It is simple but when l changes. The solution are spherical ...
LEO PHYSICS's user avatar
2 votes
1 answer
117 views

Need help to fully understand SciPy's odeint's reported step sizes, eval times, # of funct calls & total proc. time (re. question in Astronomy SE)

A recent question in Astronomy SE Numerical Programming using odeint takes more than 17 minutes got me interested in looking closer at SciPy's odeint. The problem is a modified orbital mechanical ...
uhoh's user avatar
  • 1,048
2 votes
0 answers
125 views

Scipy.root not converging even when provided with initial guesses very close to solution

I've made a previous question here and also in SO wondering why only the fsolve solver converges for the simple one dimensional unsteady conduction problem $$ \frac{\partial T}{\partial t} = \alpha \...
Klaus3's user avatar
  • 133
0 votes
2 answers
425 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
1 answer
155 views

Solve 1st order ODE in using `scipy`

I've been trying to solve the following equation $$ y(t)=-A\cdot\frac{\mathrm{d} y}{\mathrm{d} t}+B\cdot\left(\frac{\mathrm{d} y}{\mathrm{d} t}\right)^{2}+C \\ y(t=0)=y_{0}\\ $$ where $A$, $B$, and $C$...
BackSpace42's user avatar
2 votes
2 answers
1k views

Why does `scipy.optimize.minimize(...)` fail with this toy constrained minimisation case?

I'm learning scipy.optimize.minimize. I thought of a simple function to see how it works: $$f(x) = x$$ With the goal to minimise $f(x)$, subject to the constraint ...
caveman's user avatar
  • 123
1 vote
1 answer
92 views

Solving basic barystochrone problem in python

I am trying to solve $\frac{u''}{1+u'^2} - \frac{1}{2(1-u)} = 0$ subject to $u(0)=1, u(1)=0$. If I understand how to do this properly, I first do the variable substitutions: $u = y$, $y_1 = y; y_2 = y'...
Makogan's user avatar
  • 263
0 votes
0 answers
737 views

ValueError: array must not contain infs or NaNs; When using solve_ivp in the scipy library

I am solving an initial value problem using solve_ivp. The problem consists of computing the concentration profile of a set of reactions over time, given the initial concentrations and some of the ...
HWIK's user avatar
  • 23
3 votes
1 answer
122 views

Interpolating 2D data on a hemisphere in order to have $C^2$ function but no overshoot

I am interpolating a 2D dataset on a hemisphere, and I am currently using scipy.Rbf that I like for its simplicity. I am defining the norm of the interpolator with ...
Balfar's user avatar
  • 63
1 vote
1 answer
635 views

Beta function and integral value

I have two values $a$ and $b$ where $a \ge 0$ and $b \ge 0$ and I have to calculate the formula below. $$ \frac{1}{2}\int_0^1\text{abs}\left[\left( \frac{p_i^{(a - 1)} \times (1 - p_i)^{(b - 1)}}{\...
Bhavana Reddy's user avatar
1 vote
2 answers
1k views

Fix step size with scipy.integrate.RK45 and scipy.integrate.LSODA

I am trying to numerically integrate a differential equation using scipy.integrate.RK45 and/or scipy.integrate.LSODA. Now, I am trying to fix the integration step sizes of both solvers. This, however, ...
Octavius's user avatar
  • 185
3 votes
1 answer
122 views

Scipy solve_ivp sensitivity to random phase shifts

I am trying to solve a coupled system of ODE's using the solve_ivp function from scipy. The general form of the equation is given via $$\dot{y}(t) = M(t)y(t).$$ The time dependence of matrix is ...
raeel's user avatar
  • 31
3 votes
1 answer
921 views

Using the Kramers-Kronig (Hilbert) transform in Python

I am trying to use the Kramers-Kronig algorithm to transform the real and imaginary contributions to the anomalous scattering factor from a diffraction anomalous fine structure (DAFS) experiment. I ...
ayrton burgess's user avatar
2 votes
1 answer
624 views

How to extract intermediate calculation results from an SciPy ODE function in python?

I have a bit lengthier ODE function which was simulated by using Scipy solve_ivp function. During this simulation I calculated many parameters but as the output, I am taking out put only some other ...
Nis's user avatar
  • 21
2 votes
0 answers
101 views

How to save multiplication computation time between a dense vector and a not that sparse matrix?

I am trying to compute $\mathbf{X}\mathbf{u}$ for many times in my algorithm, where $\mathbf{X}\in \mathbb{R}^{n\times m}$ and $\mathbf{u} \in \mathbb{R}^{m}$. The problem is that, during the ...
Xun Maoapo's user avatar
2 votes
1 answer
2k views

scipy.optimize.root not converging and RuntimeWarning

I am trying to solve the following problem: $$ \frac{d^2y}{dx^2}=\sinh(y) $$ Where the boundary conditions are: $y(0)=-1$, and $ \frac{dy(x\rightarrow \infty)}{dx}=0 $. Through central difference ...
HWIK's user avatar
  • 23
1 vote
1 answer
454 views

Finding the parameters of a function via curve fit

I'm trying to estimate the parameters (v, n, k) defined in fit_func. I tried the default least squares fit but I couldn't find the parameters successfully. ...
Natasha's user avatar
  • 421
0 votes
0 answers
534 views

Curve fitting using a piecewise polynomial

I am trying to fit a piecewise polynomial function Code: ...
Natasha's user avatar
  • 421
0 votes
1 answer
51 views

Scipy QZ documentation

The scipy.linalg.qz function implements generalized Schur decomposition for a pair of matrices A, B such that (A, B) = (Q @ AA @ Z*, Q @ BB @ Z*), where ...
Amit Varshney's user avatar
0 votes
1 answer
1k views

Fitting a monotonically increasing spline function

I want to fit a monotonically increasing smooth spline function for a dataset Code: ...
Natasha's user avatar
  • 421
3 votes
2 answers
2k views

Inaccurate results of integration using scipy solve_ivp

I am trying to use solve_ivp to solve the following 1st order ODE: $$ \frac{d \rho}{d z} = \frac{m \theta}{(1+\theta z)} \, \rho, $$ subject to $\rho(z=0)=1$, where ...
Fryderyk's user avatar
1 vote
0 answers
252 views

SLSQP solver scipy with linear subset constraints

I have been trying to solve a least squares problem of the following form: $$ \begin{equation} \min_{\vec{x}} \frac{1}{2} \lVert f(\vec{x}) - f_{\text{target}} \rVert_{2}^2 + \alpha\Big( \frac{1-\rho}{...
bfg's user avatar
  • 11
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
0 votes
0 answers
186 views

Solving differential equations with fast oscillations using odeint

I have wrote this code to solve an equation , I know the behavior of this function has very rapid oscillations, when I RUN it gives bogus values for some "m[x]" and some "t"'s, ...
danial's user avatar
  • 11
1 vote
1 answer
347 views

How to perform FFT from plane-wave basis function coefficients to real space?

I have a 3D grid in real space of grid spacing $L$ and say 21 grid points in each direction, containing e.g. a charge distribution. This is stored as a numpy array of shape ...
Protocola's user avatar
-1 votes
1 answer
157 views

Fitting gauss-hermite-parametrization to data?

I want to fit this data. I have the following model functions. Classic gaussian: def gauss_model(x, mu, sigma): return np.exp(-0.5*((x-mu)/sigma)**2) And ...
trynerror's user avatar
1 vote
1 answer
430 views

Huygens Fresnel Diffraction integral using dblquad in python

I am attempting to create a python function to assist in calculating the following numerical integration of the Huygens Fresnel integral in the form of ...
OmegaCentauri's user avatar

1
2 3 4 5 6