The script is trying to solve Bloch equations as described in the pdf attached.
The objective is maximize function
Where
Then, we can calculate
where
Updating
as:
The optimization algorithm is as follows:
- Assume
$θ_i = 0$ (from$\theta_1$ to$\theta_n$ ). - We calculate initial
$J$ from$equation (3)$ . - Calculate all
$Y_k$ and$X_k$ as defined in$equation (4)$ . - Using
$equation (8)$ we calculate$e$ which should be a three dimensions vector. - Calculate a new set of
$\theta_k$ using$tan(\theta_k) = \frac{e_2}{e_1}$ . - Do this for all
$\theta$ . - We recalculate new
$J$ from$equation (3)$ . - Repeat steps from 3 to 7.
- We need to get J to reach 1. Only then we can stop the iteration.
This method is implemented in git branch
approach A
The method was slow and iteration time is over 50 seconds for trial.
Another approach was tried in theMaster branch
- Assume
$θ_i = 0$ (from$θ_1$ to$θ_n$ ). - Calculate a tensor with
(N,n,3,3)
dimensions whereN
: number of random$\omega$ andn
is the number of selected$\theta$ . - Calculate Y, X, and e from the tensor slicing method.
- Updating
$\theta$ and recalculate. This approach reduced the time significantly to less than 3 seconds per trial.