Help with loops in Mathematica (Hamiltonian)

1. May 6, 2013

vankoks

1. The problem statement, all variables and given/known data

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.

2. Relevant equations

See attached file

3. 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

File size:
6.2 KB
Views:
68
2. May 7, 2013

Staff: Mentor

The best way I know is to create a 2D table and use KroneckerDelta to decide the value of each element in the table.

3. May 9, 2013

Bill Simpson

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}}