Skip to content

Commit 94d59d9

Browse files
author
Guido Sterbini
committed
Centered derivative for RR computation and sanity check for the determinant
1 parent 82b9386 commit 94d59d9

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

pymask/linear_normal_form.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,12 @@ def compute_R_matrix_finite_differences(
5959
II = np.eye(6)
6060
RR = np.zeros((6, 6), dtype=np.float64)
6161
for jj, dd in enumerate([dx, dpx, dy, dpy, dzeta, ddelta]):
62-
pd=p0+II[jj]*dd
63-
RR[:,jj]=(_one_turn_map(pd, particle_on_co, tracker)-p0)/dd
64-
62+
RR[:,jj]=(_one_turn_map(p0+II[jj]*dd, particle_on_co, tracker)-
63+
_one_turn_map(p0-II[jj]*dd, particle_on_co, tracker))/(2*dd)
6564

65+
if not 0.999 < np.linalg.det(RR) < 1.001:
66+
raise ValueError('The determinant of the RR is out tolerance.')
67+
6668
if symplectify:
6769
return healy_symplectify(RR)
6870
else:

0 commit comments

Comments
 (0)