Questions tagged [python]

A general purpose high-level programming language that emphasizes ease of code syntax and readability.

Filter by
Sorted by
Tagged with
2 votes
1 answer
62 views

Spurious oscillations in solving diffusion problems using finite elements

I've been struggling with this problem for a while so I hope someone can help me here. I'm trying to solve the McNabb-Foster equations for hydrogen diffusion in metals using a simple 1D finite element ...
0 votes
1 answer
29 views

Passing additional arguments to `odeint` from `torchdiffeq` to solve an IVP

In Python I use the package torchdiffeq (as provided here) to solve initial value problems. Given an arbitrary function ...
-1 votes
0 answers
17 views

Obtain the flow, knowing the force density

I am working on a python code to reconstruct the 2d flow, knowing the continuous force density applied on the fluid (by deritative of the strain tensor), which as the form of the derivative a ...
  • 1
2 votes
1 answer
121 views

Modelling a spring interpolation

I have parameters $T$ for tension, $b$ for bounciness and $P_t$ for target value that should be approached as t goes to infinity. Currently I have written an equation like so: $\ddot{f}(t)=\frac{T(P_t-...
  • 23
-1 votes
0 answers
43 views

Solving an intermediate value in python with dense output

I wish to implement a function in python to numerically solve what we might call an intermediate value problem. By an intermediate value problem I mean the union of a final value problem (fvp) and an ...
0 votes
1 answer
127 views

Fitting a monotonically increasing spline function

I want to fit a monotonically increasing smooth spline function for a dataset Code: ...
  • 447
0 votes
1 answer
52 views

Pythonic way of finding RMS in large dataset

I am working on a fluid mechanics problem with a 4-D dataset (time,x,y,z). I am trying to find the RMS values such as $\overline{u^\prime u^\prime}$,$\overline{v^\prime v^\prime}$,$\overline{w^\prime ...
-1 votes
1 answer
31 views

'None' appears in the end of an outcome. Why? (Python 3.10 64-bit) [closed]

#Here's my code: ...
-1 votes
0 answers
99 views

Results of matrix multiplication were very different in MATLAB and Python(Numpy). Why?

I am translating some Matlab code into Python and I having some problems regarding matrix multiplication accuracy.I've compared some intermediate values in my code and I found that the results of ...
1 vote
1 answer
69 views

Fitting a rectangle-function to a signal in Python

I have a measured signal (current of a motor, turning on and off again) to which I want to fit a rectangular function in python. I came up with a reasonable ...
  • 121
1 vote
0 answers
54 views

How to find an alignment between two overlapping time series?

Context I'm working with absorbance spectral data. I have two spectra generated for a single analyte. Each spectrum was collected over two overlapping wavelength regions e.g. 8-10 micron and 9-11 ...
1 vote
0 answers
92 views

Error in implementation of Crank-Nicolson method applied to 1D TDSE?

Some context, I've posted this question on physics SE and stack overflow. The former had nothing to offer, the latter had a great commenter that agreed with the phase looking off being one of the ...
0 votes
2 answers
85 views

Is there something unique you can get out of a set of numbers?

I am currently trying to solve a problem with constraint programming. My problem is that for example you need a set of numbers and you can only have a maximum number of 9 with a required length of 6 ...
  • 143
1 vote
0 answers
98 views

Magnetic field simulation for "quasi-solenoid" - Where to start?

I would kindly ask you which (preferably free) programs / codes do you suggest for the numerical simulation of the problem described below. I am not asking for the full solution, but just want to ...
  • 11
1 vote
1 answer
60 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 ...
2 votes
1 answer
93 views

Solving nonlinear PDE in Python with LSODA

I am attempting to solve a nonlinear diffusion equation of the form $\partial_t u = \partial_x (\kappa(u) \partial_x u)$, where the conductivity function $\kappa(u)$ is a power law $\kappa = u^{5/2}$, ...
2 votes
0 answers
89 views

Numerical solution to integro-differential equation

The time dynamics of an atom interacting with a reservoir of spectral density $J(\omega)$ are obtained by solving the following integro-differential equation: $$ \frac{\mathrm{d}c(t)}{\mathrm{d}t} = - ...
  • 21
1 vote
0 answers
69 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 ...
  • 447
0 votes
0 answers
89 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, ...
  • 11
2 votes
0 answers
62 views

Numerical solution to the Tolman-Oppenheimer-Volkoff equations for any equation of state (numerical or analytical)

I've been working on a code to solve the Tolman-Oppenheimer-Volkoff (TOV) equations for a while and recently I've got it right but only for one specific equation of state, the bag model, which is not ...
1 vote
1 answer
70 views

What algorithm does CVXPY actually use to solve semidefinite programs with the constraints of the form $\sum\limits_i E_iXE_i^T \succ B$?

Crossposted on Mathematics SE CVXPY is a famous software as a solver for optimization problems. Nowadays, I use it to run a program presented in a paper, the Example 7.1, and the program runs as ...
  • 13
2 votes
0 answers
64 views

How to solve the following SDP with cvxpy in Python?

The SDP problem is $$ \min_{Z \in S^{n},Y \in S^{m}} {\rm trace}(Z) +{\rm trace}(Y)\\ {\rm s.t.} \begin{bmatrix} Y & X\\ X^T & Z \end{bmatrix} \succeq 0\\ X \in C $$ Where $C$ is a convex set....
  • 21
-1 votes
1 answer
71 views

gmsh python api ignores quad mesh option [closed]

I am trying to mesh a geometry using the gmsh python api, however it seems like my algorithm selection option (i.e. gmsh.option.setNumber("Mesh.Algorithm", 8) ) is being ignored. Can anyone ...
0 votes
1 answer
44 views

Is the Alternating-Directions Implicit method dependent on the space increment?

I am writing an Alternating-Directions Implicit Method for simple 2D diffusion ( \begin{equation*} \frac{df(x,y,t)}{dt}=D\Delta u \end{equation*}). Tridiagonal matrices are solved via Thomas ...
0 votes
0 answers
49 views

Recursion relations for integrating Gaussian functions

I'm trying to implement a numerical method used in quantum chemistry from scratch. I'm using this paper as a reference. It's also available on Sci-Hub. So, the method requires calculating integrals of ...
2 votes
1 answer
85 views

Place points at maximum distance in a convex 2D set

I need to place a given finite set of points within maximum distance of each other on 2D, constrained by a convex boundary, on Python. Honestly, I'm kind of lost. I have the explicit function to be ...
0 votes
0 answers
76 views

Advance a Interpolation

Note; No special knowledge of Pykrige is needed to answer the question, as I already mention examples in the question! Hi I would like to use Universal Kriging in my code. For this I have data that ...
  • 1
2 votes
0 answers
149 views

How can I reduce the artifact in "Thin Plate Spline" interpolation?

At the Top "right", there is the 2D-density plot of the recorded data (actual), fewer in number. Recorded data has been sampled a on the 8 arms of a regular octagon. These 8 arms are placed ...
-1 votes
1 answer
58 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 ...
2 votes
2 answers
129 views

How to ensure the numeric value is always positive in Optimization Python?

I am currently performing optimization onto a quadratic function by manually coding the algorithm: $$\min f = x^T v x - r^T x\\ \text{subject to } x \geq 0\, .$$ Here, optimizing the function without ...
1 vote
1 answer
154 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 ...
0 votes
1 answer
39 views

Get the equilibrium value in coupled ode by python

I am dealing with a coupled ODE. I have already plotted the solutions out using odeint, but I want to get the value of equilibrium. The ode looks like this: ...
0 votes
0 answers
86 views

How to solve spatially discretised PDEs (method of lines) in solve_ivp or ODEint?

I can discretise the spatial domain of a system of PDEs using the method of lines, converting the system of PDEs to a system of ODEs (with a time derivative only). These equations (for context they ...
1 vote
2 answers
108 views

Simulate Jump-Diffusion $dX_t = \mu(X_t)dt + \sigma(X_t)dW(t) + \int_{\{|c| <1 \}}g(X_t,c)\tilde{N}(dt,dc) + \int_{\{|c| \ge 1 \}}h(X_t,c)N(dt,dc)$

I would like to be able to model an SDE having the form $$dX_t = \mu(X_t)dt + \sigma(X_t)dW(t) + \int_{\{|c| <1 \}}g(X_t,c)\tilde{N}(dt,dc) + \int_{\{|c| \ge 1 \}}h(X_t,c)N(dt,dc).$$ where $W$ is a ...
1 vote
0 answers
63 views

Implementation of integration schemes for ordinary differential equations in Python and peformance comparison

I look for a book/manual where I can find implementations of different integration schemes for ordinary differential equations (like 4-th order Runge-Kutta) in Python with Numba. To be more specific, ...
0 votes
0 answers
32 views

Compute harmonic (isothermal) coordinates u-v from harmonic function field

I am trying to implement a harmonic map from a surface with a boundary to a unit circle in python. I found this algorithm by Xianfeng Gu, which is almost straight forward: harmonic mapper algorithm ...
1 vote
1 answer
266 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(\...
1 vote
0 answers
368 views

CFD in Python: Mesh Generation

I am trying to set up a 3D CFD scheme for thermal and flow modelling in Python using the finite volume method. The first concern is to build the geometry and an accompanying mesh that is efficient for ...
2 votes
1 answer
165 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)...
1 vote
0 answers
87 views

Open boundary condition for 1d wave equation with variable wave speed using finite differences

I have implemented a finite difference solver for the 1d wave equation with variable wave speed: $$ u_{tt} = c(x)u_{xx}, \hspace{10mm}c(x) = \dfrac{6 -x^2}{2} \hspace{5mm} $$ on $-2 \leq x \leq 2, t &...
3 votes
1 answer
236 views

Boundary value problem with singularity and boundary condition at infinity

I'm trying to solve the following boundary value problem on $[0,\infty]$: $$f^{\prime \prime}=-\frac{1}{r} f^{\prime}+\frac{1}{r^{2}} f+m^{2} f+2 \lambda f^{3}$$ $$f(0)=0 \ ; f(\infty)=\sqrt{-m^2/(2\...
2 votes
0 answers
110 views

Numerical instability in the inverse Laplace transform

I have a problem with Laplace inversion and my function is not numerically stable for the Laplace inverse, but I do not understand the cause of this problem. Here is my code and graph of this problem. ...
0 votes
0 answers
53 views

Examples of kinetic modeling with optimization techniques in Python

We are looking for studies or tools that implemented kinetic modeling with parameter estimation differential evolution or similar optimization techniques in Python. We are trying to understand what ...
0 votes
0 answers
29 views

How can I couple MCNP with FLUKA? To attain reactor dynamics and simulate an ADS experiment? (Under Subcritical fast system)

I'm new in Particle Physics based Computing. I want to simulate an ADS experiment (Accelerator Driven System) in subcritical fast system. I was advised to simulate the experiment with FLUKA with MCNP ...
0 votes
1 answer
132 views

How to deal with solving coupled ODE systems where variables are updated multiple times within each timestep?

I'm solving a system of coupled ODEs using Euler integration for simplicity. To make this concrete, please see the (extremely simplified) minimal working example below in Python. Imagine we have a box ...
0 votes
0 answers
56 views

Help Finding Roots

I need to refine a level curve representing an implicit function that is not numerically solvable in sympy. The initial solution set generated by matplotlib's ...
  • 143
4 votes
1 answer
234 views

Rotate a 2D contour plot through 360 degrees to create 3D plot (Python, Mayavi/Matplotlib)

I have three 1D arrays, which represent radius, height, and an intensity measured at that point. I have plotted these to create a 2D contour map. A simple example of the way in which the data is ...
  • 41
1 vote
0 answers
83 views

Help with CVXPY and Disciplined Convex Programming

I'm trying to recreate Figure 1 in this paper. This requires maximizing equation (19), which I have convinced myself is concave, but I am having trouble implementing it in CVXPY. Here is the code I ...
0 votes
0 answers
52 views

Oscillating eigenvectors for 2d-laplace operator

I am trying to calculate the eigenvectors of a Laplace-operator in 2d, with boundary conditions equal to $u=0$ if $x, y$ are outside of a rectangle defined as $(0.5, 0.5), (1.5, 1.5)$. For that I used ...
  • 543
2 votes
0 answers
106 views

solve Ax=b for outrigger A matrix python

I implement Crank-Nicolson 2D finite-difference method. I get a matrix A which is banded with 1 band above and below the main diagonal, but also contains 2 additional bands , further apart from the ...
  • 131

1
2 3 4 5
17