Skip to content

Instantly share code, notes, and snippets.

@abikoushi
Created April 17, 2025 11:49
Show Gist options
  • Save abikoushi/ecd0c2442aa29b6488876227a2df78d0 to your computer and use it in GitHub Desktop.
Save abikoushi/ecd0c2442aa29b6488876227a2df78d0 to your computer and use it in GitHub Desktop.
Learn Schrödinger's equation
makeLmat <- function (h){
x = seq(0,1,by=h)
N=length(x)
invh2 <- 1/(h^2)
res = diag(invh2, N)
res[cbind(1:(N-1),2:N)] <- -0.5*invh2
res[cbind(2:N,1:(N-1))] <- -0.5*invh2
return(list(L=res,x=x))
}
Lobj = makeLmat(0.01)
res_eigen = eigen(Lobj$L)
plot(Lobj$x, res_eigen$values, type = "l")
plot(Lobj$x, res_eigen$vector[,2], type = "l")
matplot(Lobj$x, res_eigen$vector, type = "l", col=hcl.colors(101), lty=1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment