Questions tagged [scipy]
SciPy is a Python-based ecosystem of open-source software for mathematics, science, and engineering.
253
questions
0
votes
0
answers
54
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 ...
2
votes
1
answer
79
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 ...
2
votes
1
answer
52
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 ...
1
vote
0
answers
67
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 ...
2
votes
2
answers
170
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 ...
0
votes
0
answers
21
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:
...
6
votes
1
answer
148
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 ...
1
vote
1
answer
52
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 ...
2
votes
2
answers
88
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, ...
0
votes
2
answers
42
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 ...
-1
votes
1
answer
110
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 ...
2
votes
1
answer
100
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 ...
2
votes
0
answers
86
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 \...
0
votes
2
answers
257
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}$$
$\...
0
votes
1
answer
134
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$...
2
votes
2
answers
509
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 ...
1
vote
1
answer
88
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'...
0
votes
0
answers
582
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 ...
3
votes
1
answer
116
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 ...
1
vote
1
answer
404
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)}}{\...
1
vote
2
answers
875
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, ...
3
votes
1
answer
93
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 ...
3
votes
1
answer
537
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 ...
2
votes
1
answer
337
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 ...
2
votes
0
answers
94
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 ...
2
votes
1
answer
1k
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 ...
1
vote
1
answer
241
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.
...
0
votes
0
answers
370
views
Curve fitting using a piecewise polynomial
I am trying to fit a piecewise polynomial function
Code:
...
0
votes
1
answer
49
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 ...
0
votes
1
answer
771
views
Fitting a monotonically increasing spline function
I want to fit a monotonically increasing smooth spline function for a dataset
Code:
...
3
votes
2
answers
997
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 ...
1
vote
0
answers
169
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}{...
1
vote
0
answers
85
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 ...
0
votes
0
answers
152
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, ...
1
vote
1
answer
261
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 ...
-1
votes
1
answer
123
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 ...
1
vote
1
answer
357
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 ...
1
vote
0
answers
2k
views
scipy.optimize.minimize fails to converge but result is OK
I am trying to optimize a non-linear least squares problem with scipy.optimize.minimize. I have simplified my actual problem down to the case where I am just computing the top 'principal components' ...
1
vote
1
answer
99
views
Parameter estimation simple theory question related to scipy.optimize.curve_fit
It has been a while since I have done some stats, and I have tried to fit a curve using optimize.curve_fit of parameter estimation. I am also interested in the standard deviation of the fitted ...
1
vote
1
answer
1k
views
Easy way to perform solver over pandas dataframe
I'm moving from Excel to Python and I'm trying to solve these equations:
$$\begin{align}
X_1&=\bigg[\big(3.47-\log(X_2)\big)^2+\big(\log(c)+1.22)^2\bigg]^{0.5}\\
X_2&=\frac{a}{101.32}\bigg(\...
2
votes
1
answer
313
views
2nd order differential equation coupled to integro-differential equation in python
I'm trying to solve the following equations numerically in python
$$\begin{align}
12\pi\int_0^\infty drf(r)\phi(r)r^4&=E\\
f(r)-\frac{1}{2\mu}\bigg(\frac{d^2\phi(r)}{dr^2}+\frac{2}{r}\frac{d\phi(r)...
0
votes
1
answer
2k
views
Optimal value of parameter/s from a set by scipy.optimize.minimize() method
I have this function $y = \exp(-x)$. I have a list of $x$ values and corresponding $y$ values.
...
2
votes
1
answer
103
views
Finding the correct order of eigenvectors of a parameter-dependent Hermitian matrix
so, I have a symmetric, analytic matrix $\mathbf{H}(x)$ ($x$ is real). Because $\mathbf{H}(x)$ is analytic and $x$ is real, it is possible to find analytic functions for the eigenvectors and the ...
2
votes
1
answer
115
views
SciPy ODR "Ordinary" Least Squares?
Scipy.odr has a setting for "fit types", including one for ordinary least-squares. This matches with the documentation of ODRPACK (see p. 31, Computational method).
However, the package ...
2
votes
1
answer
312
views
Can't solve second order differential equation with scipy
Most of my knowledge about numerically solving differential equations is long forgotten. Unfortunately I stumbled upon a physics problem where I need to do exactly that.
I'm trying to describe the ...
2
votes
1
answer
199
views
Global convergence behavior of several Krylov solvers in scipy.opt
In the context of mechanical simulation, where I solve the stationary action principle directly (i.e. $\nabla S = 0$ for some scalar function $S$), I use the wrapper ...
3
votes
1
answer
602
views
How to solve a BVP with known parameters?
I need to solve a boundary value problem (BVP) of second order, where the equation depends on several know parameters, which are geometric parameters and material constants.
I would like to solve this ...
1
vote
0
answers
247
views
Trouble inverting complex matrix with numpy and scipy
I have some matrix-valued, complex data $Z(f)$ with $f\in\{f_0,f_1,\dots\}$ and $Z(f_i)$ being a 3x3 matrix. I require the inverse $Z^{-1}(f)$ in my workflow. After encountering some problems with my ...
5
votes
0
answers
106
views
How to troubleshoot numerical instability using finite difference for steady-state non-linear heat conduction equation
I have a problem which I believe is numerical instability when trying to solve a heat conduction equation using finite difference. The short version is that when the parameter $I=80.3$ I get the blue ...
1
vote
1
answer
167
views
solve_ivp doesn't work with toms748
I have the following code
...