Specifying the norm of complex function #226
-
I aim to solve the nonlinear Schrödinger equation, see: https://en.wikipedia.org/wiki/Nonlinear_Schr%C3%B6dinger_equation. To do this with py-pde I need to specify the norm of a complex valued function, my guess is that I should use ψ ** 2, and specify the full equation as PDE({"ψ": f"I * 0.5* laplace(ψ)+I*(ψ *(ψ**2))"}. However, the results don't align with what I expect to see. Any tips on how to do this? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
The expression |
Beta Was this translation helpful? Give feedback.
-
Hi David, ψ * conjugate(ψ) works! However, abs(ψ)**2 gives an error for me. |
Beta Was this translation helpful? Give feedback.
The expression
ψ**2
is not calculating the squared norm, but it is equivalent toψ*ψ
. To calculate the squared norm you could either useabs(ψ)**2
, which returns a real number, orψ * conjugate(ψ)
, which returns a complex number (with vanishing imaginary part). Both versions should work equally well, although I have not tested this in detail.