12 replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/ edited Apr 13 '17 at 12:55 One could also combine this algorithm with my answer herehere to insure that the eigenvalues and eigenvectors are sorted in the correct way. This is the two-dimensional generalization of what I did in a closely related answer herehere. One could also combine this algorithm with my answer here to insure that the eigenvalues and eigenvectors are sorted in the correct way. This is the two-dimensional generalization of what I did in a closely related answer here. One could also combine this algorithm with my answer here to insure that the eigenvalues and eigenvectors are sorted in the correct way. This is the two-dimensional generalization of what I did in a closely related answer here. 11 In last code block, removed additive term in Hamiltonian left over from previous method. edited Mar 15 '15 at 16:55 Jens 88.9k66 gold badges176176 silver badges412412 bronze badges nX = 20; a = .2; Clear[v]; v[x_, y_] := 1/2 (x^2 + y^2 + x y) vGrid = Table[v[a i, a j], {i, -nX, nX}, {j, -nX, nX}]; xRange = Range[1, 2 nX + 1]; xyList = Tuples[xRange, 2]; h2 = DiagonalMatrix[ SparseArray[(vGrid[[##]] & @@@ xyList) + 2/a^2]]]] - 1/(2 a^2) Sum[ NDSolveFiniteDifferenceDerivative[i, {xRange, xRange}, "DifferenceOrder" -> 4]["DifferentiationMatrix"], {i, {{2, 0}, {0, 2}}}]; {en2, ψ2} = Eigensystem[h2, -10]; ListDensityPlot[Partition[ψ2[[5]], 2 nX + 1], PlotRange -> All]  nX = 20; a = .2; Clear[v]; v[x_, y_] := 1/2 (x^2 + y^2 + x y) vGrid = Table[v[a i, a j], {i, -nX, nX}, {j, -nX, nX}]; xRange = Range[1, 2 nX + 1]; xyList = Tuples[xRange, 2]; h2 = DiagonalMatrix[ SparseArray[(vGrid[[##]] & @@@ xyList) + 2/a^2]] - 1/(2 a^2) Sum[ NDSolveFiniteDifferenceDerivative[i, {xRange, xRange}, "DifferenceOrder" -> 4]["DifferentiationMatrix"], {i, {{2, 0}, {0, 2}}}]; {en2, ψ2} = Eigensystem[h2, -10]; ListDensityPlot[Partition[ψ2[[5]], 2 nX + 1], PlotRange -> All]  nX = 20; a = .2; Clear[v]; v[x_, y_] := 1/2 (x^2 + y^2 + x y) vGrid = Table[v[a i, a j], {i, -nX, nX}, {j, -nX, nX}]; xRange = Range[1, 2 nX + 1]; xyList = Tuples[xRange, 2]; h2 = DiagonalMatrix[ SparseArray[(vGrid[[##]] & @@@ xyList)]] - 1/(2 a^2) Sum[ NDSolveFiniteDifferenceDerivative[i, {xRange, xRange}, "DifferenceOrder" -> 4]["DifferentiationMatrix"], {i, {{2, 0}, {0, 2}}}]; {en2, ψ2} = Eigensystem[h2, -10]; ListDensityPlot[Partition[ψ2[[5]], 2 nX + 1], PlotRange -> All]  10 deleted 9 characters in body edited Mar 15 '15 at 3:06 Jens 88.9k66 gold badges176176 silver badges412412 bronze badges nX = 20; a = .2; Clear[v]; v[x_, y_] := 1/2 (x^2 + y^2 + x y) vGrid = Table[v[a i, a j], {i, -nX, nX}, {j, -nX, nX}]; xRange = Range[1, 2 nX + 1]; xyList = Tuples[xRange, 2]; h2 = DiagonalMatrix[ SparseArray[(vGrid[[##]] & @@@ xyList) + 2/a^2]] - 1/(2 a^2) Sum[ NDSolveFiniteDifferenceDerivative[i, {xRange, xRange}, "DifferenceOrder" -> 4]["DifferentiationMatrix"], {i, {{2, 0}, {0, 2}}}]; {en2, ψ2} = Eigensystem[h2, -10]; ListDensityPlot[Partition[ψ2[[5]], 2 nX + 1], PlotRange -> All]  nX = 20; a = .2; Clear[v]; v[x_, y_] := 1/2 (x^2 + y^2 + x y) vGrid = Table[v[a i, a j], {i, -nX, nX}, {j, -nX, nX}]; xRange = Range[1, 2 nX + 1]; xyList = Tuples[xRange, 2]; h2 = DiagonalMatrix[ SparseArray[(vGrid[[##]] & @@@ xyList) + 2/a^2]] - 1/(2 a^2) Sum[ NDSolveFiniteDifferenceDerivative[i, {xRange, xRange}, "DifferenceOrder" -> 4]["DifferentiationMatrix"], {i, {{2, 0}, {0, 2}}}]; {en2, ψ2} = Eigensystem[h2, -10]; ListDensityPlot[Partition[ψ2[[5]], 2 nX + 1], PlotRange -> All]  nX = 20; a = .2; Clear[v]; v[x_, y_] := 1/2 (x^2 + y^2 + x y) vGrid = Table[v[a i, a j], {i, -nX, nX}, {j, -nX, nX}]; xRange = Range[1, 2 nX + 1]; xyList = Tuples[xRange, 2]; h2 = DiagonalMatrix[ SparseArray[(vGrid[[##]] & @@@ xyList) + 2/a^2]] - 1/(2 a^2) Sum[ NDSolveFiniteDifferenceDerivative[i, {xRange, xRange}, "DifferenceOrder" -> 4]["DifferentiationMatrix"], {i, {{2, 0}, {0, 2}}}]; {en2, ψ2} = Eigensystem[h2, -10]; ListDensityPlot[Partition[ψ2[[5]], 2 nX + 1], PlotRange -> All]  9 Added built-in functionality for DifferenceOrder edited Mar 15 '15 at 2:52 Jens 88.9k66 gold badges176176 silver badges412412 bronze badges 8 Clarified meaning of grid spacing versus boundary effects edited Jun 15 '14 at 4:21 Jens 88.9k66 gold badges176176 silver badges412412 bronze badges 7 responded to comment edited Jun 15 '14 at 1:59 Jens 88.9k66 gold badges176176 silver badges412412 bronze badges 6 Generalize first approach edited Jun 14 '14 at 19:19 Jens 88.9k66 gold badges176176 silver badges412412 bronze badges 5 Generalize first approach edited Jun 14 '14 at 19:13 Jens 88.9k66 gold badges176176 silver badges412412 bronze badges 4 Added more basic approach. edited Jun 14 '14 at 18:26 Jens 88.9k66 gold badges176176 silver badges412412 bronze badges 3 Added anisotropy edited Jun 14 '14 at 5:52 Jens 88.9k66 gold badges176176 silver badges412412 bronze badges 2 added 1220 characters in body edited Jun 14 '14 at 5:36 Jens 88.9k66 gold badges176176 silver badges412412 bronze badges 1 answered Jun 14 '14 at 5:15 Jens 88.9k66 gold badges176176 silver badges412412 bronze badges