15 votes

Time and memory required to diagonalize a 18000 by 18000 matrix using numpy in python

A 20000 by 20000 double-precision complex matrix requires $20000 \times 20000 \times 8 \times 2=6.4 \mbox{gigabytes}$ of RAM. The LAPACK routines ZHEEV that will do the work for you will store the ...
Brian Borchers's user avatar
5 votes

Solving non-linear partial differential equation numerically: $u_{xx}+u_{yy}=\mathrm{e}^{u}$

You can use something like MethodOfLines.jl to solve your problem. You can modify the following example, something like this ...
mmikkelsen's user avatar
5 votes
Accepted

Understanding leapfrog integration algorithm

In the second code the full time stepping is given by three lines in main() ...
user9794's user avatar
  • 465
5 votes

Is my differential equation solving code wrong?

The cross product with $H$ acts like a complex unit in the plane that has $H$ as normal, especially if you select $H$ to be a unit vector. Components parallel to $H$ remain unchanged. What you should ...
Lutz Lehmann's user avatar
  • 5,489
4 votes

Rank-1 correction of matrix exponential

There is work on low-rank updates of matrix functions, for instance this one: Beckermann, Bernhard; Kressner, Daniel; Schweitzer, Marcel, Low-rank updates of matrix functions, SIAM J. Matrix Anal. ...
Federico Poloni's user avatar
4 votes

Understanding leapfrog integration algorithm

The first code is wrong if you have multiple particles that interact. Due to the structure of the loop, the interaction forces with particles at the start of the list are computed with the updated ...
Lutz Lehmann's user avatar
  • 5,489
4 votes

Euler's Method for fast moving particle trajectory

I tried to modify your code as little as possible and include the comments by @lightxbulb. I changed the indices in the time stepping loop and modified $F$ and $B$ so that they are being updated in ...
Julian Roth's user avatar
3 votes

Isolating decaying solutions to nonlinear second-order ode

Eliminating the constants, the approximation close to $x=0$ is $y(x)=\pi+xy'(x)$ with $y'$ nearly constant. Or one could multiply the leading terms with $2x^2y'$ and integrate $$ 2x^2y'y''+2xy'^2-2\...
Lutz Lehmann's user avatar
  • 5,489
3 votes

Approximating the solution of a non-linear ODE using Python

The canonical form of Newton's law for a particle in the classical mechanics is $ \ddot{x}= f(t,x,\dot{x}) $ That is, the second time derivative of the coordinate x is a function of time, space, and ...
Maxim Umansky's user avatar
3 votes

Free Time Dependent Schrodinger Equation with Inhomogeneous Dirichlet boundary

The TDSE is given by $$i\partial_t|\phi(t)\rangle = \hat H |\phi(t)\rangle\,.$$ Expanding the wavefunction $|\phi \rangle $ into a set of eigenfunctions of the Hamiltonian, $$ \hat H |\psi_i\rangle = ...
davidhigh's user avatar
  • 3,042
3 votes
Accepted

Issues with Simulating the Orbits of Mars and Earth using MATLAB and Runge-Kutta Method

You accidentally divided by the planet's mass twice. The force exerted by the sun on the planet is $$ \vec{F} = -\frac{G M_s m_p}{\|r\|^3} \vec{r} $$ Plugging that in to the equation of motion for the ...
helloworld922's user avatar
3 votes
Accepted

Problems solving 2D heat equation using physics-informed neural networks

The one thing that i can notice immediately where it might be going wrong is the use of ReLU Activation function for PINNs. In this problem,we have a double derivative in our loss function (Laplacian)....
ThivinAnandh's user avatar
2 votes
Accepted

Best approach to simulating dynamics on networks

I assume that your networks are sparse (most entries of the adjacency matrix are zero) and irregular (no grids and similar repeating structures). As an example, let’s look at an ODE: $\dot{x} = f(x).$ ...
Wrzlprmft's user avatar
  • 2,022
2 votes

Need help with the python code: Calculating Madelung constant CsCl crystal structure

Seems like you double count when accounting for offset. ...
mmikkelsen's user avatar
2 votes
Accepted

finding weak form of nonlinear differential equation for FEM simulation

First notice that $$ (k_3 - k_1)\sin(u)\cos(u)(u')^2 + (k_1\cos^2(u) + k_3\sin^2(u))u'' = ((k_1\cos^2(u) + k_3\sin^2(u))u')' + (k_1 - k_3)\sin(u)\cos(u)(u')^2. $$ I choose to rearrange our equation so ...
whpowell96's user avatar
  • 2,054
2 votes
Accepted

1 dimensional simulation of gravity fails

what is wrong with the simulation ? Your problem is that you are using the Euler method to derive your numerical solution. Although this method is simple to implement, it is inaccurate and unstable. ...
gandalf61's user avatar
  • 136
2 votes

In level set fluid structure interaction method why can we rewrite the elastic force in this form while there is no shear force?

Notice two things: $\nabla \left(E \left( \left| \nabla \phi \right| \right) \right) = E'(|\nabla\phi|)\nabla \left| \nabla\phi \right|$ $\nabla \left( E' \left( \left| \nabla \phi \right| \right) \...
Sthavishtha Bhopalam's user avatar
1 vote

Will hashing become vulnerable to quantum computers?

As Wolfgang pointed out, your description seems to conflate hashing with encryption. Hashing produces a small, fixed size value in a given range. The popular SHA256 uses 256 bits. A "secure" ...
Mikael Öhman's user avatar
1 vote
Accepted

Lattice Boltzmann method parallelization

DISCLAIMER: For an in-depth discussion, see Chapter 13.4 in Krüger, which addresses this in 40+ pages. Here, I merely outline two basic ideas. The core LBM consists of the steps Free stream/...
Dan Doe's user avatar
  • 904
1 vote

Approximating the solution of a non-linear ODE using Python

please find my suggestions below. For Computing b Ignoring the $\frac{db}{dt}$ on the RHS, This is an ODE with integral terms on the RHS. $$ \frac{db}{dt} = \int_t^{t1} f(b,h,t) dt $$ First thing is ...
ThivinAnandh's user avatar
1 vote
Accepted

Reverse engineering phase shift and numerical damping

For an undampened harmonic oscillator $\ddot x+w^2x=0$ you can set the velocity component to $\dot x=wy$ and then $z=x+iy$ to get $$ \dot z=wy-iwx=-iwz. $$ The implicit Euler method can now be exactly ...
Lutz Lehmann's user avatar
  • 5,489
1 vote

Numerical code to solve LLG is not preserving norm

Your forward Euler method will not preserve the norm. You need to use a different integrator (such as symplectic integrators).
user7440's user avatar
  • 617
1 vote

3D turbulent divergence free initial velocity field

One way to make your field divergence free is via the Leray Projection. The underlying idea is to identify that part of your vector field which is non-divergence free, and then subtract that from your ...
MPIchael's user avatar
  • 2,627
1 vote

Good examples of "two is easy, three is hard" in computational sciences

The example that comes to mind is quaternions. I think it is way better to quote the Wikipedia article about quaternions: Hamilton knew that the complex numbers could be interpreted as points in a ...
Navaro's user avatar
  • 156

Only top scored, non community-wiki answers of a minimum length are eligible