IPython notebook Bloch-simulation-with-exchange.ipynb
Crash course in ODEs with scipy for Bloch simulations
Let's say we have
Clearly the solution is
The simple odeint interface is easy to handle. Just give it a function handle for the derivative, a starting point, and some points where you want answers. Done.
More setup required for the generic ode interface but in exchange for a choice of integrator (Runge Kutta 4-5 in this case) comes more foot work.
Let's make sure the ODE result and the analytical solution agree.
DOPRI looks better but the real question of course is to find out whether this is due to denser points since you have to compare Cox with Granny Smith not Valencias. Short answer, dopri is more efficient.
Onwards to higher orders and applications of Bloch equations
Let's try this with some real stuff. For Bloch equations we have to move on from 1D. The ODE is: or more specifically:
ParseError: KaTeX parse error: Undefined control sequence: \eqalignno at position 1: \̲e̲q̲a̲l̲i̲g̲n̲n̲o̲{ &{dM_{x}(t)\…where the B1 field of the RF pulse is along x ("phase=0"); so rotation of only happens around x-axis. The frequency of the RF pulse is and the magnetization is being observed in the rotating frame which rotates with which can be off-resonance from the Larmor frequency by . This causes an apparent rotation of the magnetization (short since we drop the ) with that frequency .
With the above in mind, let's define a that can be used for integration:
It might be nice to check the results by using some analytical expressions for this. Some helpful discussions can be found on Brian Hargreave's website on this. He has a tutorial for this: http://mrsrl.stanford.edu/~brian/bloch/
For the near analytical solution we need to define some operators for what would constitute an RF-pulse as well as one for evolution under free precession:
Before we compare the 'analytical' solution to the ODE one, let's see whether some straightforward free precession with T1 and T2 relaxation gives us what we expect: An FID.
Now, let's see whether the evolution using our ODE further up corresponds to what we find the direct way. This is a simple sanity check.
Bonus points: Why is the envelope an exponential that decays with 2*T2?
Next steps
two-pool version
exchange terms
extension to composite evolutions: saturation pulses with exchange, hard pulse readout (FLASH), and relaxation...
larger number of pools
could this even be used for fitting?!