Questions tagged [python]

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

Filter by
Sorted by
Tagged with
1
vote
0answers
16 views

Double Integral with Gauss- Hermite for one component

I am trying to perform the following integral $$\iint_V \frac{r'\left(e^{-r'^2/2\sigma^2}\right)\left(r-r'\cos(\theta-\theta')\right)}{r^2+r'^2-2rr'\cos(\theta-\theta')}dr'dθ'$$ Using Gauss-Hermite ...
0
votes
0answers
13 views

Import Excel file into Pandas (but it is returning an xml?) [closed]

1 I am wanting to import an Excel file into panda's, in the below format. From my novice eye, it seems to be returning an XML file. Is this correct and could anyone point me towards how I get this ...
-1
votes
1answer
40 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}{\...
-1
votes
0answers
12 views

Python import Data from .txt. file with pandas down from a specific line [closed]

I am really new in Python and I hope this is the right community for my question. Sorry if it is not. I am trying to import data from a .txt file with pandas. The file looks like this: ...
2
votes
1answer
67 views

Setting up optimization problem in GEKKO

I have the following dynamical system, $\frac{d \phi}{dt} = -M^TDM\phi \tag{1}\label{1}$ $\frac{d \hat\phi}{dt} = -M^T\tilde{D}M\hat \phi \tag{2} \label{2}$ $\eqref{1}$ represents the exact ...
1
vote
2answers
44 views

Convolution in Python

I have an integral of a convolution between two functions. How can I calculate this in Python? It is a continuum convolution.
-1
votes
1answer
32 views

Numpys `tensordot` and what is happening mathematically

I've encountered a program where np.tensordot was used, so I tried looking it up but I can't really understand what this function is doing... I feel rather ...
7
votes
1answer
110 views

Numerically stable and fast sum of last K elements in sequence

Suppose I have a long, possibly infinite, sequence $x := [x_1, x_2, ...]$, and I want to use it to compute another sequence $y:=[y_1, y_2, ...]$ where each element is the sum of the last K elements of ...
0
votes
1answer
48 views

Is this behaviour normal for a Lennard-Jones monte carlo simulation?

I am simulating a Lennard-Jones fluid using MC simulation. The code always uses a reduced unit. I want to find the potential energy of the system. Periodic boundary condition implemented. I have ...
-1
votes
1answer
33 views

How to get free energy surface of a 3d Ising Spin system using Monte Carlo simulation?

I am doing a Monte Carlo Simulation of the properties of a 3D Ising Spin system. I want to get the free energy surface of the spin system from the simulation. It is a magnetization vs free energy ...
0
votes
0answers
37 views

2D diffusion equation using Finite Volume Method

i am working on an assignment problem: Consider a two-dimensional rectangular plate of dimension L = 1 m in the x direction and H = 2 m in the y direction. The plate material has constant thermal ...
0
votes
1answer
59 views

Why the magnetisation shows abrupt behaviour for this 3D ising spin system

I am trying to simulate a 3D Ising spin system (+1 & -1) using Monte Carlo Metropolis Algorithm. I want to get different physical quantities from this simulation like magnetization, Average Energy,...
2
votes
0answers
33 views

Lexicographically order matrix into a vector

I am trying to implement the algorithm contained in this article here. It is about solving a 2 and 2.5D Fredholm integral, focused on bidimensional NMR experiments. I've made significant progress, ...
4
votes
1answer
112 views

Absence of Discontinuity in Specific Heat Plot Simulated by Ising Model

I am working on 2D Ising model, when I plot "specific heat vs temperature", I can't see any discontinuity at critical temperature around Tc ~ 2.7K. I am enclosing results of all other thermodynamic ...
-1
votes
0answers
35 views

attempt to solve nonlinear 2nd order O.D.E using scipy.integrate.odeint resulting in error :Excess work done on this call (perhaps wrong Dfun type)

I have written a python script to solve the ordinary differential equation $$f''+f''f^2+f'^2-f-f^3 = 2ff'^2 + f'^2f''$$ after substituting in $x_1 = f$, $x_2 = f'$ i get the two first-order ODE's $$...
-1
votes
0answers
31 views

How to integrate using the composite trapezoidal rule without numpy/scipy [duplicate]

For this I am using Python. I need to use the composite rule of Boole to integrate a function. I know there is a function in numpy (numpy.trapz) that does the integration, but I haven't found one for ...
-1
votes
0answers
31 views

Verification of Code

I am currently stuck with implementing some code. I need to plot L^2 against ∆t but I am not sure how to write L^2 as code, I have the numerical and exact solutions in my code and I am currently ...
-1
votes
1answer
62 views

Solving a large system of coupled ode. (Python)

I really have a problem here. I have not found a solution yet. The system I need to solve similar to this:(Basic idea) $$c_1 = \dfrac{dx}{dr}+y$$ $$c_2 = \dfrac{dy}{dr}+x$$ Both $c_1/ c_2$ are ...
0
votes
1answer
70 views

Simple Harmonic Motion using the leapfrog method

I have to use the leapfrog method to solve the simple harmonic oscillator and I having trouble writing it in code. This is what we were given in class $$ \frac{v_{n+1/2}-v_{n-1/2}}{\Delta t}=-\...
-1
votes
0answers
14 views

What are the inputs of the function addCurveLoops() in gmsh-API?

In gmsh-API i got the function addCurveLoops(), i understand what it does, but i do not understand the inputs, the documentation says: Add a curve loop (a ...
-1
votes
0answers
26 views

I cannot get matplotlib QM tunnelling animation to work in Jupyter, please help

I am trying to learn programming to be able to create visualizations of concepts in math and physics. I have found the language/tools I want to use (MATLAB and Matplotlib). Now I am at the stage of ...
-1
votes
1answer
88 views

If not MATLAB, what software/programming language should I use to simulate/animate wave functions in various potentials + more? (example given)

I want to integrate programming into my learning in math and science in a very specific way. I want to create visualizations and simulations of concepts I am learning. When I learn a numerical method ...
0
votes
0answers
78 views

Parallel plate capacitor as simple superposition of Coulomb-fields

I am trying to calculate and visualize the electric field inside and outside of a parallel plate capacitor by assuming a uniform distribution of point charges on each plate and by adding up the ...
4
votes
1answer
71 views

Arbitrary Precision Optimization Libraries?

Are there any well-known optimization libraries (ideally with Python bindings or even in Python) supporting (unconstrained) minimization (of $f:\mathbb{R}^n \to \mathbb{R}$ for $n$ for $n\sim 10^1,10^...
0
votes
0answers
27 views

Why am I not getting the flat phase when Fourier-transform a Fourier-limited Gaussian pulse?

I have been trying to obtain a spectrum and a spectral phase of a Gaussian pulse using the Fast Fourier Transform provided with numpy library in Python. Here are ...
1
vote
0answers
15 views

SHREC 2010 Descriptors

I will appreciate if I may find someone how can clarify for me the part regarding the quality of feature descriptor, shown in the figure below: and this screenshot is from the article: SHREC All my ...
5
votes
2answers
186 views

Fastest Way to Mutiply $10^4$ 2x2 Matrices

In a code that I work with (written in python, but also tagging as matlab because numpy is so close and I could use it if need be), we use a transfer matrix method to compute the properties of a ...
3
votes
2answers
180 views

Solving ODE with “Jumpy” Coefficients

I'm numerically solving a linear coupled ODE of the form $$y^{\prime}(t) = \hat{M}(t)y(t)=\left[\begin{array}{cc}0& A(t)\\ B(t)& 0\end{array}\right]y(t),$$ and the difficulty I'm running into ...
1
vote
0answers
31 views

sequence\ flow analysis with score- beginner data scientist

I'm trying to create a model that will give me the best parts that lead to a maximized score out of a sequence. my data(spark rdd) looks like this: ("dan", "john", "john", "guy", 45) ("john", "dan",...
3
votes
1answer
57 views

Evaluate 3D Shape Descriptor

I'm trying to create my own 3d shape descriptor, the idea is that how I may evaluate how much my descriptor is well and good? What I checked is that they evaluate descriptors through shape matching, ...
4
votes
1answer
189 views

Solving coupled differential equations in Python, 2nd order

I have a system of coupled differential equations, one of which is second-order. I am looking for a way to solve them in Python. I would be extremely grateful for any advice on how can I do that! $k$...
-3
votes
1answer
47 views

How do I graph this in python? [closed]

$$ y=\cases{-\sqrt{|x|}, \quad x\le0\\\sqrt{x}, \quad x>0} $$ I've tried graphing this in python, but can't seem to figure it out. Does anyone know how to do this by chance?
1
vote
0answers
53 views

How to minimize a integral function using a constant step gradient method in Python?

I am developing a practical work of the following system of ode \begin{align}x'(t) &= k_1h(t) - (k_2+k_3)x(t)\\ y'(t) &= k_3x(t)\end{align} and $z(t) = (1-k_4)(x(t)+y(t))+k_4h(t)$, where $h(...
0
votes
0answers
39 views

Propagation of a Gaussian beam using FFT

I am trying to simulate the propagation of a gaussian beam through a lens using an FFT approach. I tried to implement the approach described by Couairon in this paper at page 43: https://link....
2
votes
1answer
144 views

Efficient ways to numerically evaluate matrix exponentials

What are some computationally efficient ways to solve matrix exponentials, i.e. functions of the form : f(X)=$e^{X}$, where X is a square matrix ? So far I have been able to diagonalise some ...
3
votes
1answer
109 views

Calculation of Mean Square Displacement for Brownian dynamics system with Lennard Jones interactions in python3

I have a problem getting a sensible result for the Mean Square Displacement (MSD) for a simulation of $N$ particles under Brownian dynamics with Lennard-Jones interaction between them with or without ...
11
votes
3answers
4k views

How much more work is it to code math models in Python, compared to working with Matlab?

If one had to code up a new dynamical system for a research group at a university, and the university has a Matlab total headcount license so that one could code in Matlab, are there any benefits to ...
2
votes
2answers
83 views

Implementing Gelfand’s formula for the spectral radius in Python - lack of convergence

For context: Gelfand's formula for the spectral radius is $\lim_{k\rightarrow \infty}|A^k|^{1/k}$ where $|\cdot|$ is any well-defined operator norm. I naively coded a function to calculate the $k$th ...
0
votes
0answers
151 views

Numerically solving a partial differential equation in python with Runge Kutta 4

I'm supposed to solve the following partial differential equation in python using Runge-Kutta 4 method in time. $$ \frac{\partial}{\partial t}v(y,t)=Lv(t,y) $$ where $L$ is the following linear ...
2
votes
1answer
137 views

Numerical Solution to Rayleigh Plesset Equation in Python

I have been trying to numerically solve the Rayleigh-Plesset equation for a sonoluminescence bubble in Python. You can read about this phenomenon here: https://iopscience.iop.org/article/10.1088/0143-...
5
votes
1answer
78 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
76 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
59 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 \...
6
votes
2answers
1k views

Runge-Kutta in the presence of an attractor

Suppose you are solving a system of equations numerically that possesses an attractor (no matter the initial conditions set, all the different solutions will approach a specific set of values that ...
6
votes
0answers
111 views

fastest way to compute many small dot products

I have two n-by-3 blocks contiguous in memory ("n vectors of length 3") and I'd like to compute the dot product between each of the rows as fast as possible. In numpy, using ...
2
votes
1answer
56 views

How to obtain only the value of my variable using scipy.optimize.minimize

when I minimize a function using scipy.optimize.minimize I get a big list of things as a result, but I would like to only get the value of my variable, this is my code : ...
1
vote
1answer
48 views

Attempting to perturb ODE when initial condition is equilibrium point does not work

I have the following system of differential equations: $$ x' = ax- cy + e1 $$ $$y' = by- dx + e2 $$ for variables $x,y$ and parameters $a,b,c,d,e1,e2$. I'd like to solve this in python, which is ...
3
votes
1answer
68 views

Calculate Transformation Matrix between two sensors

My question is if I can calculate the transformation matrix between two sensors. Each sensor provides a $4\times 4$ matrix for every timestep recorded. The sensors are moving and have some noise in ...
3
votes
2answers
104 views

Chebyshev differentiation via FFT with a domain [a,b]

I want to ask something about Chebyshev differentiation via FFT, which can be used to obtain with spectral accuracy the derivative of a smooth function. See for instance this code in python, which ...
5
votes
0answers
145 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 ...

1
2 3 4 5
12