Help with loops in Mathematica (Hamiltonian)

AI Thread Summary
The discussion focuses on generating a specific Hamiltonian matrix for the Schrödinger equation using Mathematica. The user seeks to create a 7x7 matrix where diagonal elements are defined by ΔE, off-diagonal elements by complex conjugates of Ω(rf), and other elements are set to zero. A proposed solution involves using a 2D table and the KroneckerDelta function to determine the values of each matrix element. The provided Mathematica code successfully constructs the desired Hamiltonian matrix based on these criteria. This approach effectively translates the logic from a C programming perspective into Mathematica syntax.
vankoks
Messages
1
Reaction score
0

Homework Statement



I have an assignment for my thesis to make Hamiltonian for Schrodinger equation. I won't go into physics part of it, because that is well understood.

I need to somehow generate a specific matrix for Hamiltonian (H).

Please see the attached file of what I need to get.

Homework Equations



See attached file

The Attempt at a Solution



I have thought of solution for this in C, but I don't know how to syntax this in Mathematica.

The solution for this in C would be to generate 7x7 matrix where elements (i,j) would be made by:

If
i=j
ΔE
Else
If
i-j=1
Ω(rf) complex conjugate
i-j=-1
Ω(rf)
Else
0
 

Attachments

  • hamiltonian.png
    hamiltonian.png
    6.6 KB · Views: 472
Physics news on Phys.org
The best way I know is to create a 2D table and use KroneckerDelta to decide the value of each element in the table.
 
In[1]:= H = Table[
Which[
i == j, g*\[Mu]B*ToExpression["m" <> ToString]*B,
i - j == 1, Conjugate[\[CapitalOmega]rf],
i - j == -1, \[CapitalOmega]rf,
True, 0
], {i, 7}, {j, 7}
]

Out[1]= {{B g m1 \[Mu]B, \[CapitalOmega]rf, 0, 0, 0, 0, 0},
{Conjugate[\[CapitalOmega]rf], B g m2 \[Mu]B, \[CapitalOmega]rf, 0, 0, 0, 0},
{0, Conjugate[\[CapitalOmega]rf], B g m3 \[Mu]B, \[CapitalOmega]rf, 0, 0, 0},
{0, 0, Conjugate[\[CapitalOmega]rf], B g m4 \[Mu]B, \[CapitalOmega]rf, 0, 0},
{0, 0, 0, Conjugate[\[CapitalOmega]rf], B g m5 \[Mu]B, \[CapitalOmega]rf, 0},
{0, 0, 0, 0, Conjugate[\[CapitalOmega]rf], B g m6 \[Mu]B, \[CapitalOmega]rf},
{0, 0, 0, 0, 0, Conjugate[\[CapitalOmega]rf], B g m7 \[Mu]B}}
 

Similar threads

Replies
5
Views
3K
Replies
156
Views
10K
Replies
1
Views
2K
Replies
1
Views
662
Replies
9
Views
3K
Replies
10
Views
3K
Replies
3
Views
2K
Replies
4
Views
2K
Back
Top