All Questions
Tagged with numerical-methods physics
59 questions
1
vote
0
answers
104
views
Trouble Reproducing Kuramoto Model Simulation from Paper Using PyTorch and 4th Order Runge-Kutta in Python
I am using the 4th order Runge-Kutta method to simulate the Kuramoto model.
I need to use the GPU, so I am using pytorch for calculations.
I am trying to reproduce a paper's result (DOI: 10.1103/...
1
vote
0
answers
177
views
Periodic boundary conditions in a 2D array
I need to implement the following boundary conditions in my Python code f(0, x) = f(-1, x) = 0 and f(y, 0) = f(y, N) (periodic in the second index).
My code doesn't seem to work. F is a numerical ...
0
votes
1
answer
311
views
Is the Euler-Cromer method? Or is it incorrect?
k=3;m=123
eulerC_x=[A]
eulerC_v=[0]
eulerC_t=[0]
c=0
for z in np.arange(t_euler,t_max,dt_euler):
a=-(k/m)*eulerC_x[c]
eulerC_v.append(eulerC_v[c]+a*dt_euler)
eulerC_x.append(eulerC_x[c]+...
0
votes
0
answers
58
views
Calculating the length of a cord line based on forces
In 3D, I need to find the cord length based on forces that describe the cord.
I tried to do this, based on the following code with the following inputs:
H the constant horizontal force
q_verti the ...
1
vote
1
answer
480
views
Python: How do I properly use integrate.solve_bvp for the 2-D projectile motion of an object with air resistance
I'm fairly new to programming and am trying to write a program using the inbuilt function 'integrate.solve_bvp' to determinine the trajectory of a projectile subject to boundary conditions.
I'm not by ...
-1
votes
1
answer
739
views
How to write Bessel function using power series method in Python without Sympy?
I am studying Computational Physics with a lecturer who always ask me to write Python and Matlab code without using instant code (a library that gives me final answer without showing mathematical ...
2
votes
1
answer
143
views
Euler method in c++; Values getting too big too fast
i am trying to solve the equation of motion for a particle with mass m attached to a spring with a spring constant k. Both are set to 1 however.
The algorithm looks like this:
My (attempted) solution,...
1
vote
1
answer
247
views
Why does my solution for the quantum harmonic oscillator blow up?
I am using odeint to solve for the energy levels of the QHO (Griffiths problem 2.55).
I am integrating from x=0 to x=3. When I plot the results, I expect to see half of a gaussian with a tail that ...
0
votes
0
answers
213
views
Error in implementation of Crank-Nicolson method applied to 1D TDSE?
This is more of a computational physics problem, and I've asked it on physics stack exchange, but no answers on there. This is, I suppose, a mix of the disciplines on here and there (and maybe even ...
1
vote
1
answer
158
views
Orbit of the Earth - numerical methods leapfrog
edit:
I get these plots now from earths orbit. However, total energy looks not right. Should it not be oscillating between 0?
Thanks again!
I am attempting this numerical methods homework exercise ...
1
vote
0
answers
22
views
Why dt2 in limit_jerk in ros controller
I'm now reading ros controller source codes and trying to customize my own controller.
And I have a question about the limit_jerk in speed_limiter.cpp, which isn't a coding problem, maybe physics or ...
0
votes
0
answers
68
views
How do I solve a system of equations with Eulers Method?
So I have one problem for motion. The problem is finding for which angle, a object would fall off a sphere. Suppose the sphere is frictionless and all that, so it just slides off. Logically this would ...
0
votes
1
answer
622
views
Numerically Solving A Multivariate Differential Equation Without odeint
I am curious. I know this can be solved by using odeint, but I'm trying to do it from scratch, and I've encountered an interesting behaviour.
Assume a simple oscillator, of equation m * x_ddot + k * x ...
1
vote
0
answers
434
views
Implementing the Lanczos algorithm into C++ for a quantum anharmonic oscillator
Firstly, I would like to mention that I am a complete beginner when it comes to coding, let alone C++, so bear with me, as I need complete guidance. My task is to implement the Lanczos algorithm for ...
0
votes
1
answer
84
views
numerical prediction of a pendulums motion in python not predicting properly
I'm working on a numerical prediction of a pendulums motion for a project. while running the program I've noticed the time between each peak (when the value reaches the same theta value as the ...
1
vote
1
answer
867
views
fortran : invalid memory reference
I encountered this error while solving the diffusion equation on fortran using alternating directional implicit(ADI) method.
Program received signal SIGSEGV: Segmentation fault - invalid memory ...
2
votes
2
answers
411
views
Creating and updating 3 index matrix in Python
I'm trying to create a three index matrix that contains 1 value (V) for every node of a numerical spatial mesh (xyz) (real world problem: the electrostatic potential created by finite-paralell- plates ...
0
votes
1
answer
134
views
Equations of motions vs Verlet: Collision ignored?
I initially coded my simulation using the standard equations of motions, but as is known, it ended up being quite unstable, even if it technically worked.
If we take x(t) to be the position-function ...
2
votes
1
answer
2k
views
Is Gauss quadrature always a good option for know analytical functions?
What are the limitations of Gauss quadratures? I know that if I'm integrating, for example, a data set a Gauss quadrature won't be the best option, but if I know the function analytically is there any ...
0
votes
0
answers
336
views
Numerical solutions of unsteady 2D heat equation in python producing error incorrectly
I am trying to implement two numerical solutions. A forward Euler and a second order Runge-Kutta for the unsteady 2D heat equation with periodic boundary conditions. I am using a 3 point central ...
1
vote
2
answers
775
views
Numerical integration: Why does my orbit simulation yield the wrong result?
I read Feynman's Lecture on Physics Chapter 9 and tried to my own simulation. I used Riemann integrals to calculate velocity and position. Although all start-entry is same, my orbit look's like a ...
2
votes
1
answer
942
views
Understanding the local truncation error of an adaptive Runge Kutta integrator
I'm implementing an RKF4(5) integrator, and I can't figure out if my code is working and I don't understand local truncation error, or if my code isn't working.
I apologize for the size of the code ...
0
votes
2
answers
3k
views
How do I solve a 2nd order differential equation for projectile motion with air resistance?
the equation is:
d^2 r/dt^2 = -c/m (dr/dt)+g
where r is the position of the projectile, c is the drag coefficient, m is the mass of the projectile and g is the acceleration due to gravity.
Assuming ...
1
vote
1
answer
772
views
How to find the electric field from the potential?
That's my script to find a potentiel in a ionization room:
# Programme de résolution de l'équation de Laplace
# par la méthode de Gauss-seidel
# importation des librairies
import numpy as np
import ...
5
votes
1
answer
3k
views
Solving coupled PDE with python
I do not understand how to solve for the eta and V in my coupled PDE equations using python or a python ode solver. (Or is it possible to do a numerical solution for these couple equations without a ...
1
vote
2
answers
635
views
Estimate velocity on a spring by iterative approach
The problem:
Consider a system with a mass and a spring as shown in the picture below. The stiffness of the spring and the mass of the object are known. Therefore, if the spring is stretched the ...
0
votes
0
answers
448
views
Free fall simulation: problems defining varying air resistance
So this is the situation: I'm doing a coding project which will model Felix Baumgartner's free fall from a height of around 40 km. As part of this project, I'm supposed to demonstrate the use of the ...
0
votes
2
answers
4k
views
Angular spectrum method using python
I am trying to numerically propagate a given (electric) field using the angular spectrum method. For this I am following "Principles and Applications of Fourier Optics" (Robert K. Tyson) Chapter 3, ...
2
votes
1
answer
848
views
Fastest algorithm for computing 3-D curl
I'm trying to write a section of code that computes the curl of a vector field numerically to second order with periodic boundary conditions. However, the algorithm I made is very slow and I'm ...
0
votes
0
answers
485
views
Vector Plot of Electric Field (Laplace's Equation)
I have solved Laplace's equation for a 2D square box analytically, and would like to plot the electric field vectors as a function of y and x. https://www.youtube.com/watch?v=ws3LIfWxfcM This is a ...
0
votes
0
answers
588
views
Problems with creating Poincare surface plots for the Henon-Heiles Hamiltonian using symplectic integrator
I am trying to plot the poincaré surface sections for the Henon- Heiles Hamiltonian using the symplectic integrator Ruth of 3rd order, but I am having some problems because after several steps the ...
1
vote
1
answer
333
views
How to calculate the period of a pendulum
The task is to calculate the period of a pendulum. One of my values is blowing up as it approaches t=0, which is confusing me a lot. I also don't know if any of my values are correct.
The following ...
0
votes
1
answer
893
views
Morton Reverse Encoding for a 3D grid
I have a 3D grid/array say u[nx+2][ny+2][nz+2]. The trailing +2 corresponds to two layers of halo cells in each of the three dimension x,y,z. I have another grid which allows for refinement(using ...
2
votes
1
answer
582
views
How to integrate object space acceleration to world space position (2D)
I want to double integrate 2D acceleration data in object coordinates to get 2D position in world coordinates. The object always points in the direction of velocity (assume e.g. a train).
So I tried ...
0
votes
1
answer
456
views
Numerical methods to solve function with restricted domain
Methods to solve(root finding) the function with the restricted domain.
Suppose to solve the function
$sin^{-1}(\sqrt{E_n/V}) +a*\sqrt{2mE_n/h^2}=n*\pi$
where
$E_n,V,a,m,h n$ were all positive.
...
2
votes
4
answers
1k
views
Multiplying parenthesis to get a polynomial in python
I was asked to do the newton polynomial interpolation and I was able to write the main code.
https://en.wikipedia.org/wiki/Newton_polynomial
But there is still one small thing that I am not able to ...
2
votes
1
answer
7k
views
solving 1D Schrödinger equation with Numerov method (python)
I'm currently trying to solve the 1D Schrödinger eq. (time independent) with the Numerov method. The derivation of the method is clear to me but I have some problems with the implementation. I tried ...
0
votes
3
answers
228
views
How to define a function in python that takes as an input mathematica function and it's argument and apply to it.
I want to define a function that takes arguments as a mathematical function , it's arguments, and number of iterations (I am looking for the zeros of the function with the fixpoint theorem).
I know ...
0
votes
0
answers
526
views
python numpy.libalg.eigh() returns wrong eigen vectors. why?
For a brief info, I was tasked to model a wave function for a quantum particle imprisoned in a parabolic potential (this problem is related to quantum harmonic oscillator).
I used matrix method for ...
0
votes
2
answers
1k
views
How to include a random perturbation noise in initial solution by numerical simulation
I am solving NLSE equation with a potential term in matlab by split-step method. I want to see solution in it numerically. u=sech(x) is the initial guess solution in that numerical algorithm. But I ...
2
votes
0
answers
871
views
How do I solve equations using the Scharfetter-Gummel scheme in FiPy?
I'm trying to use FiPy to simulate solar cells but I'm struggling to get reasonable results even for simple test cases.
My test problem is an abrupt 1D p-n homojunction in the dark in equilibrium. ...
0
votes
1
answer
51
views
MATLAB - Getting an NaN error
I'm trying to generate plots of a galactic orbit in a particular potential. My code is given by
function Eulersystem_MNmodel()
parsec = 3.08*10^18;
r_1 = 8.5*1000.0*parsec; % This converts ...
0
votes
2
answers
579
views
I need help setting up matrices to solve using Gaussian elimination in Python
Apologies in advance to those who has to read through my poor coding skill
The objective of this coding is to first develop a 17x17 matrix and solve for the 17 unknowns using methods presented in ...
0
votes
2
answers
1k
views
How to make gaussian package move in numerical simulation of a square barrier in C
I am trying to use Gaussian packages to study the transmission probability via Trotter-Suzuki formula and fast Fourier transform (FFT) when confronted with a square barrier, just as done in this ...
1
vote
1
answer
128
views
sampling 2-dimensional surface: how many sample points along X & Y axes?
I have a set of first 25 Zernike polynomials. Below are shown few in Cartesin co-ordinate system.
z2 = 2*x
z3 = 2*y
z4 = sqrt(3)*(2*x^2+2*y^2-1)
:
:
z24 = sqrt(14)*(15*(x^2+y^2)^2-20*(x^2+y^2)+6)...
1
vote
1
answer
6k
views
Lennard-Jones potential simulation
import pygame
import random
import numpy as np
import matplotlib.pyplot as plt
import math
number_of_particles = 70
my_particles = []
background_colour = (255,255,255)
width, height = 500, 500
sigma =...
1
vote
1
answer
112
views
Simple way to numerically integrate constrained dynamics?
For example, a simple pendulum (string length = 1) can be described as
mx'' = λ*2x
my'' = -mg + λ*2y
x^2 + y^2 - 1 = 0
where the primes mean derivatives w.r.t time, and λ*2x and λ*2y are the ...