# Questions tagged [python]

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

535 questions
Filter by
Sorted by
Tagged with
52 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 ...
48 views

88 views

### Fenics: solving the same PDE multiple times

I am new to Fenics and just started reading the tutorial Solving PDEs in Python. For simplicity, we can refer to simplest example, page 17 (the linear poisson equation), despite not necessary. My ...
56 views

### Weighted QR Implementation

Say I want a QR decomposition of matrix $A$, where orthogonality of $Q$ is with respect to a generic non-degenerate positive-definite bilinear form $\phi$ (in my case, $\phi$ is "defined" by a finite-...
85 views

### Implementing structured grid boundary conditions using NumPy arrays?

I am making a toy code in Python to solve the advection equation $$u_t + cu_x = 0$$ with, for example, periodic boundary conditions. Background information The numerical grid is specified like this: ...
67 views

### Runge-Kutta for PID and system in separate calculations without filter

I need to calculate a closed-loop system in Python; specifically, obtain the PID response and then use the output to obtain the system response sample-by-sample with my own loop. For this, I am ...
30 views

### Implementation of Lanczos method that returns tridiagonal matrix

The Lanczos method can be used to obtain extremal eigenpairs of sparse symmetric or hermitian matrices. I know there are several implementations of the Lanczos method (as well as Arnoldi, Davidson, ...
35 views

### Least square approximation of a polynomial with a constraint on the derivative in Python

I'm trying to fit a polynomial of the third degree through a number of points. This could be a very simple problem when not constraining the derivative. I found some promising solutions using CVXPY to ...
125 views

97 views

### MINLP with GEKKO - Modeling discrete variables

I'm trying to define a MINLP optimization problem with GEKKO in Python, and I want to use some variables with fixed values. For my first variable, x1, I need to define the following values (as would ...
92 views

### Heisenberg Model python : Specific heat capacity for spin 2

I have the correct plot for specific heat capacity when I am using the formula which is $C_V$ = differentiation of entropy with respect to temperature. However, When I try to calculate $C_V$, by using ...
43 views

### Doing computations on a very large numpy array: streaming the calculation vs out-of-core memory

I am trying to perform a calculation in numpy that depends on several parameters, and involved the creation of many intermediate arrays. These intermediate steps involve integrals over more parameters....
70 views

### How to translate Python infinitely big integer into Cython?

I want to factorize very huge numbers (e.g. 100-bits, 200-bits numbers) with Cython. Hi everyone, I implemented the Elliptic Curve Method for factorization into Python 3.6. Now, I want to speed up my ...
39 views

### Can I use matplotlib to plot the surface of a 3D body?

If Matplotlib could volume render, I would not ask this question. But it can't. Can I however instead use Matplotlib to plot the surface of a 3D body? I.e. is there a way to (i) triangulate the ...
123 views

### Problem concerning a part of a simulation for the Ising Model

I was wondering if anyone could help me with a simulation in Python (there is a small part of the code where I have a question) about the Ising model. First, I wanted to get the magnetization $M$ ...
72 views

### What is a good library in Python for correlated fits in both the $x$ and $y$ data?

I have $x$ and $y$ data, both of which have their own covariance matrices. scipy.optimize.curve_fit will accept a covariance matrix for the $y$ data, called ...
72 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 ...
48 views

### Simulate friction arround steady-state point

When simulating a friction dynamic system, I have come to a problem when approaching steady-state. In the example below, a box moves along a surface with a certain friction coefficient: ...
58 views

### Getting Extremal Rays of Cone

So I have a set of linear homogeneous equations $A\vec{x}=0$. I would like to solve this for non-negative solutions. I can solve the system in general and I get the two vectors that span the solution ...
16 views

### Find all recurring subgraphs/patterns of maximal size in a single undirected, labeled, connected graph

I would like to identify all subgraphs of maximal size (maximum number of nodes) that are recurrent in a single undirected, labeled, connected graph. I provide exemples of input and expected output ...
53 views

### Efficient algorithm to determine the intersection volume of simple convex polyhedra

TLDR: Is there an efficient algorithm to compute the intersection of polyhedra with 8 or fewer vertices? I have two sets of FEM meshes for one geometry (one exhibiting a skin effect). I have to ...
141 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(\...
78 views

### How to perform local sensitivity analysis for partial differential equations

I am looking for a way to do local sensitivity analysis for PDEs, preferably in Python. I get the impression that discretizing the equation then treating it as an ODE could work; however, would that ...
45 views

### Draw contour line to represent multiple contours

I have 5 data sets, each includes multiple scatter points. If I use the geom_path function in R, I could obtain 5 contours like the following graph shows. Those five contours are annotated outlines ...
54 views

63 views

### How to use Wolfe-Powell step-size control in quasi-Newton method?

I'm trying to find the minimum of a function using the quasi-Newton method with the Broyden-Fletcher-Goldfarb-Shanno (BFGS) algorithm. But I want to change the following implementation, so that: 1) ...
361 views

### Python: vectorizing a structured linear system solve

Overview I am looking for a way to solve a structured linear system in Python without using a for loop (preferably using vectorization, if possible). Background Consider the following linear system:...
48 views

### Interpolating the gradient of a cylindrically symmetric potential field that's 'supposed to' obey the Laplace equation?

The script below tries to implement a Jacobi iterative relaxation of a potential field for an electrostatic lens. It's hot-off-the-press and I've just started to debug and look for things to test it ...