# Rのヤコビ行列などの計算

```python
import sympy as sy
from sympy import sqrt

t = sy.Symbol("t")
l1, l2, l3 = sy.symbols("l1, l2, l3")
xi = sy.Symbol("xi")
c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, L0, r = sy.symbols(
    "c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, L0, r"
)

q = sy.Matrix([[l1, l2, l3]]).T

def task_R(q):
    """線形化された回転行列"""

    l1 = q[0,0]
    l2 = q[1,0]
    l3 = q[2,0]

    A1 = l1**2 + l2**2 + l3**2 - l1*l2 - l1*l3 - l2*l3
    A2 = 2*l1 - l2 - l3
    A3 = l2 - l3
    A4 = 3*L0 + l1 + l2 + l3

    R11 = 1 - (A2**2 * A1**4 * xi**10) / (c1 * r**10) + \
        (A2**2 * A1**3 * xi**8) / (c1 * r**8) - \
            (A2**2 * A1**2 * xi**6) / (c3 * r**6) + \
                (A1 * A2**2 * xi**4) / (c4 * r**4) - \
                    (A2**2 * xi**2) / (c5 * r**2)

    R12 = (sqrt(3) * A2 * A3 * A1**4 * xi**10) / (c1 * r**10) + \
        (sqrt(3) * A2 * A3 * A1**3 * xi**8) / (c2 * r**8) - \
            (sqrt(3) * A2 * A3 * A1**2 * xi**6) / (c3 * r**6) + \
                (sqrt(3) * A2 * A3 * A1 * xi**4) / (c4 * r**4) - \
                    (sqrt(3) * A2 * A3 * xi**2) / (c5 * r**2)

    R13 = -(2 * A2 * A1**4 * xi**9) / (c6 * r**9) + \
        (4 * A2 * A1**3 * xi**7) / (c7 * r**7) - \
            (2 * A2 * A1**2 * xi**5) / (c8 * r**5) + \
                (2 * A2 * A1 * xi**3) / (c9 * r**3) - \
                    (A2 * xi) / (3 * r)

    R22 = 1 - (A3**2 * A1**4 * xi**10) / (c10 * r**10) + \
        (A3**2 * A1**3 * xi**8) / (c11 * r**8) - \
            (A3**2 * A1**2 * xi**6) / (c12 * r**6) + \
                (A3**2 * A1 * xi**4) / (c13 * r**4) - \
                    (A3**2 * xi**2) / (6 * r**2)

    R23 = -(2*sqrt(3) * A3 * A1**4 * xi**9) / (c6 * r**9) + \
        (4*sqrt(3) * A3 * A1**3 * xi**7) / (c7 * r**7) - \
            (2*sqrt(3) * A3 * A1**2 * xi**5) / (c8 * r**5) + \
                (2*sqrt(3) * A3 * A1 * xi**3) / (c9 * r**3) - \
                    (sqrt(3) * A3 * xi) / (3 * r)

    R33 = 1 - (2 * xi**2 * A1) / (9 * r**2) + \
        (2 * xi**4 * A1**2) / (c14 * r**4) - \
            (4 * xi**6 * A1**3) / (c3 * r**6) + \
                (2 * xi**8 * A1**4) / (c15 * r**8) - \
                    (4 * xi**10 * A1**5) / (c1 * r**10)

    R21 = R12
    R31 = -R13
    R32 = -R23

    return sy.Matrix([
        [R11, R12, R13],
        [R21, R22, R23],
        [R31, R32, R33],
    ])

R = task_R(q)
R
```

$\displaystyle \left[\begin{matrix}1 - \frac{\xi^{2} \left(2 l_{1} - l_{2} - l_{3}\right)^{2}}{c_{5} r^{2}} + \frac{\xi^{4} \left(2 l_{1} - l_{2} - l_{3}\right)^{2} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{4} r^{4}} - \frac{\xi^{6} \left(2 l_{1} - l_{2} - l_{3}\right)^{2} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{3} r^{6}} + \frac{\xi^{8} \left(2 l_{1} - l_{2} - l_{3}\right)^{2} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{1} r^{8}} - \frac{\xi^{10} \left(2 l_{1} - l_{2} - l_{3}\right)^{2} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{4}}{c_{1} r^{10}} & - \frac{\sqrt{3} \xi^{2} \left(l_{2} - l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right)}{c_{5} r^{2}} + \frac{\sqrt{3} \xi^{4} \left(l_{2} - l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{4} r^{4}} - \frac{\sqrt{3} \xi^{6} \left(l_{2} - l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{3} r^{6}} + \frac{\sqrt{3} \xi^{8} \left(l_{2} - l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{2} r^{8}} + \frac{\sqrt{3} \xi^{10} \left(l_{2} - l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{4}}{c_{1} r^{10}} & - \frac{\xi \left(2 l_{1} - l_{2} - l_{3}\right)}{3 r} + \frac{\xi^{3} \left(4 l_{1} - 2 l_{2} - 2 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{9} r^{3}} - \frac{\xi^{5} \left(4 l_{1} - 2 l_{2} - 2 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{8} r^{5}} + \frac{\xi^{7} \left(8 l_{1} - 4 l_{2} - 4 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{7} r^{7}} - \frac{\xi^{9} \left(4 l_{1} - 2 l_{2} - 2 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{4}}{c_{6} r^{9}}\\- \frac{\sqrt{3} \xi^{2} \left(l_{2} - l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right)}{c_{5} r^{2}} + \frac{\sqrt{3} \xi^{4} \left(l_{2} - l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{4} r^{4}} - \frac{\sqrt{3} \xi^{6} \left(l_{2} - l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{3} r^{6}} + \frac{\sqrt{3} \xi^{8} \left(l_{2} - l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{2} r^{8}} + \frac{\sqrt{3} \xi^{10} \left(l_{2} - l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{4}}{c_{1} r^{10}} & 1 - \frac{\xi^{2} \left(l_{2} - l_{3}\right)^{2}}{6 r^{2}} + \frac{\xi^{4} \left(l_{2} - l_{3}\right)^{2} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{13} r^{4}} - \frac{\xi^{6} \left(l_{2} - l_{3}\right)^{2} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{12} r^{6}} + \frac{\xi^{8} \left(l_{2} - l_{3}\right)^{2} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{11} r^{8}} - \frac{\xi^{10} \left(l_{2} - l_{3}\right)^{2} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{4}}{c_{10} r^{10}} & - \frac{\sqrt{3} \xi \left(l_{2} - l_{3}\right)}{3 r} + \frac{2 \sqrt{3} \xi^{3} \left(l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{9} r^{3}} - \frac{2 \sqrt{3} \xi^{5} \left(l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{8} r^{5}} + \frac{4 \sqrt{3} \xi^{7} \left(l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{7} r^{7}} - \frac{2 \sqrt{3} \xi^{9} \left(l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{4}}{c_{6} r^{9}}\\\frac{\xi \left(2 l_{1} - l_{2} - l_{3}\right)}{3 r} - \frac{\xi^{3} \left(4 l_{1} - 2 l_{2} - 2 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{9} r^{3}} + \frac{\xi^{5} \left(4 l_{1} - 2 l_{2} - 2 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{8} r^{5}} - \frac{\xi^{7} \left(8 l_{1} - 4 l_{2} - 4 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{7} r^{7}} + \frac{\xi^{9} \left(4 l_{1} - 2 l_{2} - 2 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{4}}{c_{6} r^{9}} & \frac{\sqrt{3} \xi \left(l_{2} - l_{3}\right)}{3 r} - \frac{2 \sqrt{3} \xi^{3} \left(l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{9} r^{3}} + \frac{2 \sqrt{3} \xi^{5} \left(l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{8} r^{5}} - \frac{4 \sqrt{3} \xi^{7} \left(l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{7} r^{7}} + \frac{2 \sqrt{3} \xi^{9} \left(l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{4}}{c_{6} r^{9}} & 1 - \frac{2 \xi^{2} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{9 r^{2}} - \frac{4 \xi^{6} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{3} r^{6}} + \frac{2 \xi^{8} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{4}}{c_{15} r^{8}} + \frac{2 \xi^{4} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{14} r^{4}} - \frac{4 \xi^{10} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{5}}{c_{1} r^{10}}\end{matrix}\right]$

計算

```python
dRdl1 = sy.diff(R, l1)
dRdl1
```

$\displaystyle \left[\begin{matrix}- \frac{\xi^{2} \left(8 l_{1} - 4 l_{2} - 4 l_{3}\right)}{c_{5} r^{2}} + \frac{\xi^{4} \left(2 l_{1} - l_{2} - l_{3}\right)^{3}}{c_{4} r^{4}} + \frac{\xi^{4} \left(8 l_{1} - 4 l_{2} - 4 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{4} r^{4}} - \frac{\xi^{6} \left(2 l_{1} - l_{2} - l_{3}\right)^{2} \left(4 l_{1} - 2 l_{2} - 2 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{3} r^{6}} - \frac{\xi^{6} \left(8 l_{1} - 4 l_{2} - 4 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{3} r^{6}} + \frac{\xi^{8} \left(2 l_{1} - l_{2} - l_{3}\right)^{2} \left(6 l_{1} - 3 l_{2} - 3 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{1} r^{8}} + \frac{\xi^{8} \left(8 l_{1} - 4 l_{2} - 4 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{1} r^{8}} - \frac{\xi^{10} \left(2 l_{1} - l_{2} - l_{3}\right)^{2} \left(8 l_{1} - 4 l_{2} - 4 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{1} r^{10}} - \frac{\xi^{10} \left(8 l_{1} - 4 l_{2} - 4 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{4}}{c_{1} r^{10}} & - \frac{2 \sqrt{3} \xi^{2} \left(l_{2} - l_{3}\right)}{c_{5} r^{2}} + \frac{\sqrt{3} \xi^{4} \left(l_{2} - l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right)^{2}}{c_{4} r^{4}} + \frac{2 \sqrt{3} \xi^{4} \left(l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{4} r^{4}} - \frac{\sqrt{3} \xi^{6} \left(l_{2} - l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right) \left(4 l_{1} - 2 l_{2} - 2 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{3} r^{6}} - \frac{2 \sqrt{3} \xi^{6} \left(l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{3} r^{6}} + \frac{\sqrt{3} \xi^{8} \left(l_{2} - l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right) \left(6 l_{1} - 3 l_{2} - 3 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{2} r^{8}} + \frac{2 \sqrt{3} \xi^{8} \left(l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{2} r^{8}} + \frac{\sqrt{3} \xi^{10} \left(l_{2} - l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right) \left(8 l_{1} - 4 l_{2} - 4 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{1} r^{10}} + \frac{2 \sqrt{3} \xi^{10} \left(l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{4}}{c_{1} r^{10}} & - \frac{2 \xi}{3 r} + \frac{\xi^{3} \left(2 l_{1} - l_{2} - l_{3}\right) \left(4 l_{1} - 2 l_{2} - 2 l_{3}\right)}{c_{9} r^{3}} + \frac{4 \xi^{3} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{9} r^{3}} - \frac{\xi^{5} \left(4 l_{1} - 2 l_{2} - 2 l_{3}\right)^{2} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{8} r^{5}} - \frac{4 \xi^{5} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{8} r^{5}} + \frac{\xi^{7} \left(6 l_{1} - 3 l_{2} - 3 l_{3}\right) \left(8 l_{1} - 4 l_{2} - 4 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{7} r^{7}} + \frac{8 \xi^{7} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{7} r^{7}} - \frac{\xi^{9} \left(4 l_{1} - 2 l_{2} - 2 l_{3}\right) \left(8 l_{1} - 4 l_{2} - 4 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{6} r^{9}} - \frac{4 \xi^{9} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{4}}{c_{6} r^{9}}\\- \frac{2 \sqrt{3} \xi^{2} \left(l_{2} - l_{3}\right)}{c_{5} r^{2}} + \frac{\sqrt{3} \xi^{4} \left(l_{2} - l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right)^{2}}{c_{4} r^{4}} + \frac{2 \sqrt{3} \xi^{4} \left(l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{4} r^{4}} - \frac{\sqrt{3} \xi^{6} \left(l_{2} - l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right) \left(4 l_{1} - 2 l_{2} - 2 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{3} r^{6}} - \frac{2 \sqrt{3} \xi^{6} \left(l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{3} r^{6}} + \frac{\sqrt{3} \xi^{8} \left(l_{2} - l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right) \left(6 l_{1} - 3 l_{2} - 3 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{2} r^{8}} + \frac{2 \sqrt{3} \xi^{8} \left(l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{2} r^{8}} + \frac{\sqrt{3} \xi^{10} \left(l_{2} - l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right) \left(8 l_{1} - 4 l_{2} - 4 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{1} r^{10}} + \frac{2 \sqrt{3} \xi^{10} \left(l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{4}}{c_{1} r^{10}} & \frac{\xi^{4} \left(l_{2} - l_{3}\right)^{2} \left(2 l_{1} - l_{2} - l_{3}\right)}{c_{13} r^{4}} - \frac{\xi^{6} \left(l_{2} - l_{3}\right)^{2} \left(4 l_{1} - 2 l_{2} - 2 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{12} r^{6}} + \frac{\xi^{8} \left(l_{2} - l_{3}\right)^{2} \left(6 l_{1} - 3 l_{2} - 3 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{11} r^{8}} - \frac{\xi^{10} \left(l_{2} - l_{3}\right)^{2} \left(8 l_{1} - 4 l_{2} - 4 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{10} r^{10}} & \frac{2 \sqrt{3} \xi^{3} \left(l_{2} - l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right)}{c_{9} r^{3}} - \frac{2 \sqrt{3} \xi^{5} \left(l_{2} - l_{3}\right) \left(4 l_{1} - 2 l_{2} - 2 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{8} r^{5}} + \frac{4 \sqrt{3} \xi^{7} \left(l_{2} - l_{3}\right) \left(6 l_{1} - 3 l_{2} - 3 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{7} r^{7}} - \frac{2 \sqrt{3} \xi^{9} \left(l_{2} - l_{3}\right) \left(8 l_{1} - 4 l_{2} - 4 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{6} r^{9}}\\\frac{2 \xi}{3 r} - \frac{\xi^{3} \left(2 l_{1} - l_{2} - l_{3}\right) \left(4 l_{1} - 2 l_{2} - 2 l_{3}\right)}{c_{9} r^{3}} - \frac{4 \xi^{3} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{9} r^{3}} + \frac{\xi^{5} \left(4 l_{1} - 2 l_{2} - 2 l_{3}\right)^{2} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{8} r^{5}} + \frac{4 \xi^{5} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{8} r^{5}} - \frac{\xi^{7} \left(6 l_{1} - 3 l_{2} - 3 l_{3}\right) \left(8 l_{1} - 4 l_{2} - 4 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{7} r^{7}} - \frac{8 \xi^{7} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{7} r^{7}} + \frac{\xi^{9} \left(4 l_{1} - 2 l_{2} - 2 l_{3}\right) \left(8 l_{1} - 4 l_{2} - 4 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{6} r^{9}} + \frac{4 \xi^{9} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{4}}{c_{6} r^{9}} & - \frac{2 \sqrt{3} \xi^{3} \left(l_{2} - l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right)}{c_{9} r^{3}} + \frac{2 \sqrt{3} \xi^{5} \left(l_{2} - l_{3}\right) \left(4 l_{1} - 2 l_{2} - 2 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{8} r^{5}} - \frac{4 \sqrt{3} \xi^{7} \left(l_{2} - l_{3}\right) \left(6 l_{1} - 3 l_{2} - 3 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{7} r^{7}} + \frac{2 \sqrt{3} \xi^{9} \left(l_{2} - l_{3}\right) \left(8 l_{1} - 4 l_{2} - 4 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{6} r^{9}} & - \frac{2 \xi^{2} \left(2 l_{1} - l_{2} - l_{3}\right)}{9 r^{2}} - \frac{4 \xi^{6} \left(6 l_{1} - 3 l_{2} - 3 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{3} r^{6}} + \frac{2 \xi^{8} \left(8 l_{1} - 4 l_{2} - 4 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{15} r^{8}} + \frac{2 \xi^{4} \left(4 l_{1} - 2 l_{2} - 2 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{14} r^{4}} - \frac{4 \xi^{10} \left(10 l_{1} - 5 l_{2} - 5 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{4}}{c_{1} r^{10}}\end{matrix}\right]$

```python
print(dRdl1)
```

    Matrix([[-xi**2*(8*l1 - 4*l2 - 4*l3)/(c5*r**2) + xi**4*(2*l1 - l2 - l3)**3/(c4*r**4) + xi**4*(8*l1 - 4*l2 - 4*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)/(c4*r**4) - xi**6*(2*l1 - l2 - l3)**2*(4*l1 - 2*l2 - 2*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)/(c3*r**6) - xi**6*(8*l1 - 4*l2 - 4*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**2/(c3*r**6) + xi**8*(2*l1 - l2 - l3)**2*(6*l1 - 3*l2 - 3*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**2/(c1*r**8) + xi**8*(8*l1 - 4*l2 - 4*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**3/(c1*r**8) - xi**10*(2*l1 - l2 - l3)**2*(8*l1 - 4*l2 - 4*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**3/(c1*r**10) - xi**10*(8*l1 - 4*l2 - 4*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**4/(c1*r**10), -2*sqrt(3)*xi**2*(l2 - l3)/(c5*r**2) + sqrt(3)*xi**4*(l2 - l3)*(2*l1 - l2 - l3)**2/(c4*r**4) + 2*sqrt(3)*xi**4*(l2 - l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)/(c4*r**4) - sqrt(3)*xi**6*(l2 - l3)*(2*l1 - l2 - l3)*(4*l1 - 2*l2 - 2*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)/(c3*r**6) - 2*sqrt(3)*xi**6*(l2 - l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**2/(c3*r**6) + sqrt(3)*xi**8*(l2 - l3)*(2*l1 - l2 - l3)*(6*l1 - 3*l2 - 3*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**2/(c2*r**8) + 2*sqrt(3)*xi**8*(l2 - l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**3/(c2*r**8) + sqrt(3)*xi**10*(l2 - l3)*(2*l1 - l2 - l3)*(8*l1 - 4*l2 - 4*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**3/(c1*r**10) + 2*sqrt(3)*xi**10*(l2 - l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**4/(c1*r**10), -2*xi/(3*r) + xi**3*(2*l1 - l2 - l3)*(4*l1 - 2*l2 - 2*l3)/(c9*r**3) + 4*xi**3*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)/(c9*r**3) - xi**5*(4*l1 - 2*l2 - 2*l3)**2*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)/(c8*r**5) - 4*xi**5*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**2/(c8*r**5) + xi**7*(6*l1 - 3*l2 - 3*l3)*(8*l1 - 4*l2 - 4*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**2/(c7*r**7) + 8*xi**7*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**3/(c7*r**7) - xi**9*(4*l1 - 2*l2 - 2*l3)*(8*l1 - 4*l2 - 4*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**3/(c6*r**9) - 4*xi**9*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**4/(c6*r**9)], [-2*sqrt(3)*xi**2*(l2 - l3)/(c5*r**2) + sqrt(3)*xi**4*(l2 - l3)*(2*l1 - l2 - l3)**2/(c4*r**4) + 2*sqrt(3)*xi**4*(l2 - l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)/(c4*r**4) - sqrt(3)*xi**6*(l2 - l3)*(2*l1 - l2 - l3)*(4*l1 - 2*l2 - 2*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)/(c3*r**6) - 2*sqrt(3)*xi**6*(l2 - l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**2/(c3*r**6) + sqrt(3)*xi**8*(l2 - l3)*(2*l1 - l2 - l3)*(6*l1 - 3*l2 - 3*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**2/(c2*r**8) + 2*sqrt(3)*xi**8*(l2 - l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**3/(c2*r**8) + sqrt(3)*xi**10*(l2 - l3)*(2*l1 - l2 - l3)*(8*l1 - 4*l2 - 4*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**3/(c1*r**10) + 2*sqrt(3)*xi**10*(l2 - l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**4/(c1*r**10), xi**4*(l2 - l3)**2*(2*l1 - l2 - l3)/(c13*r**4) - xi**6*(l2 - l3)**2*(4*l1 - 2*l2 - 2*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)/(c12*r**6) + xi**8*(l2 - l3)**2*(6*l1 - 3*l2 - 3*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**2/(c11*r**8) - xi**10*(l2 - l3)**2*(8*l1 - 4*l2 - 4*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**3/(c10*r**10), 2*sqrt(3)*xi**3*(l2 - l3)*(2*l1 - l2 - l3)/(c9*r**3) - 2*sqrt(3)*xi**5*(l2 - l3)*(4*l1 - 2*l2 - 2*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)/(c8*r**5) + 4*sqrt(3)*xi**7*(l2 - l3)*(6*l1 - 3*l2 - 3*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**2/(c7*r**7) - 2*sqrt(3)*xi**9*(l2 - l3)*(8*l1 - 4*l2 - 4*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**3/(c6*r**9)], [2*xi/(3*r) - xi**3*(2*l1 - l2 - l3)*(4*l1 - 2*l2 - 2*l3)/(c9*r**3) - 4*xi**3*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)/(c9*r**3) + xi**5*(4*l1 - 2*l2 - 2*l3)**2*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)/(c8*r**5) + 4*xi**5*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**2/(c8*r**5) - xi**7*(6*l1 - 3*l2 - 3*l3)*(8*l1 - 4*l2 - 4*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**2/(c7*r**7) - 8*xi**7*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**3/(c7*r**7) + xi**9*(4*l1 - 2*l2 - 2*l3)*(8*l1 - 4*l2 - 4*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**3/(c6*r**9) + 4*xi**9*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**4/(c6*r**9), -2*sqrt(3)*xi**3*(l2 - l3)*(2*l1 - l2 - l3)/(c9*r**3) + 2*sqrt(3)*xi**5*(l2 - l3)*(4*l1 - 2*l2 - 2*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)/(c8*r**5) - 4*sqrt(3)*xi**7*(l2 - l3)*(6*l1 - 3*l2 - 3*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**2/(c7*r**7) + 2*sqrt(3)*xi**9*(l2 - l3)*(8*l1 - 4*l2 - 4*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**3/(c6*r**9), -2*xi**2*(2*l1 - l2 - l3)/(9*r**2) - 4*xi**6*(6*l1 - 3*l2 - 3*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**2/(c3*r**6) + 2*xi**8*(8*l1 - 4*l2 - 4*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**3/(c15*r**8) + 2*xi**4*(4*l1 - 2*l2 - 2*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)/(c14*r**4) - 4*xi**10*(10*l1 - 5*l2 - 5*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**4/(c1*r**10)]])

```python
dRdl2 = sy.diff(R, l2)
dRdl2
```

$\displaystyle \left[\begin{matrix}- \frac{\xi^{2} \left(- 4 l_{1} + 2 l_{2} + 2 l_{3}\right)}{c_{5} r^{2}} + \frac{\xi^{4} \left(- 4 l_{1} + 2 l_{2} + 2 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{4} r^{4}} + \frac{\xi^{4} \left(- l_{1} + 2 l_{2} - l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right)^{2}}{c_{4} r^{4}} - \frac{\xi^{6} \left(- 4 l_{1} + 2 l_{2} + 2 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{3} r^{6}} - \frac{\xi^{6} \left(- 2 l_{1} + 4 l_{2} - 2 l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right)^{2} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{3} r^{6}} + \frac{\xi^{8} \left(- 4 l_{1} + 2 l_{2} + 2 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{1} r^{8}} + \frac{\xi^{8} \left(- 3 l_{1} + 6 l_{2} - 3 l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right)^{2} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{1} r^{8}} - \frac{\xi^{10} \left(- 4 l_{1} + 2 l_{2} + 2 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{4}}{c_{1} r^{10}} - \frac{\xi^{10} \left(- 4 l_{1} + 8 l_{2} - 4 l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right)^{2} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{1} r^{10}} & \frac{\sqrt{3} \xi^{2} \left(l_{2} - l_{3}\right)}{c_{5} r^{2}} - \frac{\sqrt{3} \xi^{2} \left(2 l_{1} - l_{2} - l_{3}\right)}{c_{5} r^{2}} + \frac{\sqrt{3} \xi^{4} \left(l_{2} - l_{3}\right) \left(- l_{1} + 2 l_{2} - l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right)}{c_{4} r^{4}} - \frac{\sqrt{3} \xi^{4} \left(l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{4} r^{4}} + \frac{\sqrt{3} \xi^{4} \left(2 l_{1} - l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{4} r^{4}} - \frac{\sqrt{3} \xi^{6} \left(l_{2} - l_{3}\right) \left(- 2 l_{1} + 4 l_{2} - 2 l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{3} r^{6}} + \frac{\sqrt{3} \xi^{6} \left(l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{3} r^{6}} - \frac{\sqrt{3} \xi^{6} \left(2 l_{1} - l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{3} r^{6}} + \frac{\sqrt{3} \xi^{8} \left(l_{2} - l_{3}\right) \left(- 3 l_{1} + 6 l_{2} - 3 l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{2} r^{8}} - \frac{\sqrt{3} \xi^{8} \left(l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{2} r^{8}} + \frac{\sqrt{3} \xi^{8} \left(2 l_{1} - l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{2} r^{8}} + \frac{\sqrt{3} \xi^{10} \left(l_{2} - l_{3}\right) \left(- 4 l_{1} + 8 l_{2} - 4 l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{1} r^{10}} - \frac{\sqrt{3} \xi^{10} \left(l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{4}}{c_{1} r^{10}} + \frac{\sqrt{3} \xi^{10} \left(2 l_{1} - l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{4}}{c_{1} r^{10}} & \frac{\xi}{3 r} + \frac{\xi^{3} \left(- l_{1} + 2 l_{2} - l_{3}\right) \left(4 l_{1} - 2 l_{2} - 2 l_{3}\right)}{c_{9} r^{3}} - \frac{2 \xi^{3} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{9} r^{3}} - \frac{\xi^{5} \left(- 2 l_{1} + 4 l_{2} - 2 l_{3}\right) \left(4 l_{1} - 2 l_{2} - 2 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{8} r^{5}} + \frac{2 \xi^{5} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{8} r^{5}} + \frac{\xi^{7} \left(- 3 l_{1} + 6 l_{2} - 3 l_{3}\right) \left(8 l_{1} - 4 l_{2} - 4 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{7} r^{7}} - \frac{4 \xi^{7} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{7} r^{7}} - \frac{\xi^{9} \left(- 4 l_{1} + 8 l_{2} - 4 l_{3}\right) \left(4 l_{1} - 2 l_{2} - 2 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{6} r^{9}} + \frac{2 \xi^{9} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{4}}{c_{6} r^{9}}\\\frac{\sqrt{3} \xi^{2} \left(l_{2} - l_{3}\right)}{c_{5} r^{2}} - \frac{\sqrt{3} \xi^{2} \left(2 l_{1} - l_{2} - l_{3}\right)}{c_{5} r^{2}} + \frac{\sqrt{3} \xi^{4} \left(l_{2} - l_{3}\right) \left(- l_{1} + 2 l_{2} - l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right)}{c_{4} r^{4}} - \frac{\sqrt{3} \xi^{4} \left(l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{4} r^{4}} + \frac{\sqrt{3} \xi^{4} \left(2 l_{1} - l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{4} r^{4}} - \frac{\sqrt{3} \xi^{6} \left(l_{2} - l_{3}\right) \left(- 2 l_{1} + 4 l_{2} - 2 l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{3} r^{6}} + \frac{\sqrt{3} \xi^{6} \left(l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{3} r^{6}} - \frac{\sqrt{3} \xi^{6} \left(2 l_{1} - l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{3} r^{6}} + \frac{\sqrt{3} \xi^{8} \left(l_{2} - l_{3}\right) \left(- 3 l_{1} + 6 l_{2} - 3 l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{2} r^{8}} - \frac{\sqrt{3} \xi^{8} \left(l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{2} r^{8}} + \frac{\sqrt{3} \xi^{8} \left(2 l_{1} - l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{2} r^{8}} + \frac{\sqrt{3} \xi^{10} \left(l_{2} - l_{3}\right) \left(- 4 l_{1} + 8 l_{2} - 4 l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{1} r^{10}} - \frac{\sqrt{3} \xi^{10} \left(l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{4}}{c_{1} r^{10}} + \frac{\sqrt{3} \xi^{10} \left(2 l_{1} - l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{4}}{c_{1} r^{10}} & - \frac{\xi^{2} \left(2 l_{2} - 2 l_{3}\right)}{6 r^{2}} + \frac{\xi^{4} \left(l_{2} - l_{3}\right)^{2} \left(- l_{1} + 2 l_{2} - l_{3}\right)}{c_{13} r^{4}} + \frac{\xi^{4} \left(2 l_{2} - 2 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{13} r^{4}} - \frac{\xi^{6} \left(l_{2} - l_{3}\right)^{2} \left(- 2 l_{1} + 4 l_{2} - 2 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{12} r^{6}} - \frac{\xi^{6} \left(2 l_{2} - 2 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{12} r^{6}} + \frac{\xi^{8} \left(l_{2} - l_{3}\right)^{2} \left(- 3 l_{1} + 6 l_{2} - 3 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{11} r^{8}} + \frac{\xi^{8} \left(2 l_{2} - 2 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{11} r^{8}} - \frac{\xi^{10} \left(l_{2} - l_{3}\right)^{2} \left(- 4 l_{1} + 8 l_{2} - 4 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{10} r^{10}} - \frac{\xi^{10} \left(2 l_{2} - 2 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{4}}{c_{10} r^{10}} & - \frac{\sqrt{3} \xi}{3 r} + \frac{2 \sqrt{3} \xi^{3} \left(l_{2} - l_{3}\right) \left(- l_{1} + 2 l_{2} - l_{3}\right)}{c_{9} r^{3}} + \frac{2 \sqrt{3} \xi^{3} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{9} r^{3}} - \frac{2 \sqrt{3} \xi^{5} \left(l_{2} - l_{3}\right) \left(- 2 l_{1} + 4 l_{2} - 2 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{8} r^{5}} - \frac{2 \sqrt{3} \xi^{5} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{8} r^{5}} + \frac{4 \sqrt{3} \xi^{7} \left(l_{2} - l_{3}\right) \left(- 3 l_{1} + 6 l_{2} - 3 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{7} r^{7}} + \frac{4 \sqrt{3} \xi^{7} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{7} r^{7}} - \frac{2 \sqrt{3} \xi^{9} \left(l_{2} - l_{3}\right) \left(- 4 l_{1} + 8 l_{2} - 4 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{6} r^{9}} - \frac{2 \sqrt{3} \xi^{9} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{4}}{c_{6} r^{9}}\\- \frac{\xi}{3 r} - \frac{\xi^{3} \left(- l_{1} + 2 l_{2} - l_{3}\right) \left(4 l_{1} - 2 l_{2} - 2 l_{3}\right)}{c_{9} r^{3}} + \frac{2 \xi^{3} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{9} r^{3}} + \frac{\xi^{5} \left(- 2 l_{1} + 4 l_{2} - 2 l_{3}\right) \left(4 l_{1} - 2 l_{2} - 2 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{8} r^{5}} - \frac{2 \xi^{5} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{8} r^{5}} - \frac{\xi^{7} \left(- 3 l_{1} + 6 l_{2} - 3 l_{3}\right) \left(8 l_{1} - 4 l_{2} - 4 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{7} r^{7}} + \frac{4 \xi^{7} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{7} r^{7}} + \frac{\xi^{9} \left(- 4 l_{1} + 8 l_{2} - 4 l_{3}\right) \left(4 l_{1} - 2 l_{2} - 2 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{6} r^{9}} - \frac{2 \xi^{9} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{4}}{c_{6} r^{9}} & \frac{\sqrt{3} \xi}{3 r} - \frac{2 \sqrt{3} \xi^{3} \left(l_{2} - l_{3}\right) \left(- l_{1} + 2 l_{2} - l_{3}\right)}{c_{9} r^{3}} - \frac{2 \sqrt{3} \xi^{3} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{9} r^{3}} + \frac{2 \sqrt{3} \xi^{5} \left(l_{2} - l_{3}\right) \left(- 2 l_{1} + 4 l_{2} - 2 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{8} r^{5}} + \frac{2 \sqrt{3} \xi^{5} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{8} r^{5}} - \frac{4 \sqrt{3} \xi^{7} \left(l_{2} - l_{3}\right) \left(- 3 l_{1} + 6 l_{2} - 3 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{7} r^{7}} - \frac{4 \sqrt{3} \xi^{7} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{7} r^{7}} + \frac{2 \sqrt{3} \xi^{9} \left(l_{2} - l_{3}\right) \left(- 4 l_{1} + 8 l_{2} - 4 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{6} r^{9}} + \frac{2 \sqrt{3} \xi^{9} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{4}}{c_{6} r^{9}} & - \frac{2 \xi^{2} \left(- l_{1} + 2 l_{2} - l_{3}\right)}{9 r^{2}} - \frac{4 \xi^{6} \left(- 3 l_{1} + 6 l_{2} - 3 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{3} r^{6}} + \frac{2 \xi^{8} \left(- 4 l_{1} + 8 l_{2} - 4 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{15} r^{8}} + \frac{2 \xi^{4} \left(- 2 l_{1} + 4 l_{2} - 2 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{14} r^{4}} - \frac{4 \xi^{10} \left(- 5 l_{1} + 10 l_{2} - 5 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{4}}{c_{1} r^{10}}\end{matrix}\right]$

```python
print(dRdl2)
```

    Matrix([[-xi**2*(-4*l1 + 2*l2 + 2*l3)/(c5*r**2) + xi**4*(-4*l1 + 2*l2 + 2*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)/(c4*r**4) + xi**4*(-l1 + 2*l2 - l3)*(2*l1 - l2 - l3)**2/(c4*r**4) - xi**6*(-4*l1 + 2*l2 + 2*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**2/(c3*r**6) - xi**6*(-2*l1 + 4*l2 - 2*l3)*(2*l1 - l2 - l3)**2*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)/(c3*r**6) + xi**8*(-4*l1 + 2*l2 + 2*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**3/(c1*r**8) + xi**8*(-3*l1 + 6*l2 - 3*l3)*(2*l1 - l2 - l3)**2*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**2/(c1*r**8) - xi**10*(-4*l1 + 2*l2 + 2*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**4/(c1*r**10) - xi**10*(-4*l1 + 8*l2 - 4*l3)*(2*l1 - l2 - l3)**2*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**3/(c1*r**10), sqrt(3)*xi**2*(l2 - l3)/(c5*r**2) - sqrt(3)*xi**2*(2*l1 - l2 - l3)/(c5*r**2) + sqrt(3)*xi**4*(l2 - l3)*(-l1 + 2*l2 - l3)*(2*l1 - l2 - l3)/(c4*r**4) - sqrt(3)*xi**4*(l2 - l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)/(c4*r**4) + sqrt(3)*xi**4*(2*l1 - l2 - l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)/(c4*r**4) - sqrt(3)*xi**6*(l2 - l3)*(-2*l1 + 4*l2 - 2*l3)*(2*l1 - l2 - l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)/(c3*r**6) + sqrt(3)*xi**6*(l2 - l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**2/(c3*r**6) - sqrt(3)*xi**6*(2*l1 - l2 - l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**2/(c3*r**6) + sqrt(3)*xi**8*(l2 - l3)*(-3*l1 + 6*l2 - 3*l3)*(2*l1 - l2 - l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**2/(c2*r**8) - sqrt(3)*xi**8*(l2 - l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**3/(c2*r**8) + sqrt(3)*xi**8*(2*l1 - l2 - l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**3/(c2*r**8) + sqrt(3)*xi**10*(l2 - l3)*(-4*l1 + 8*l2 - 4*l3)*(2*l1 - l2 - l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**3/(c1*r**10) - sqrt(3)*xi**10*(l2 - l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**4/(c1*r**10) + sqrt(3)*xi**10*(2*l1 - l2 - l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**4/(c1*r**10), xi/(3*r) + xi**3*(-l1 + 2*l2 - l3)*(4*l1 - 2*l2 - 2*l3)/(c9*r**3) - 2*xi**3*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)/(c9*r**3) - xi**5*(-2*l1 + 4*l2 - 2*l3)*(4*l1 - 2*l2 - 2*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)/(c8*r**5) + 2*xi**5*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**2/(c8*r**5) + xi**7*(-3*l1 + 6*l2 - 3*l3)*(8*l1 - 4*l2 - 4*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**2/(c7*r**7) - 4*xi**7*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**3/(c7*r**7) - xi**9*(-4*l1 + 8*l2 - 4*l3)*(4*l1 - 2*l2 - 2*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**3/(c6*r**9) + 2*xi**9*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**4/(c6*r**9)], [sqrt(3)*xi**2*(l2 - l3)/(c5*r**2) - sqrt(3)*xi**2*(2*l1 - l2 - l3)/(c5*r**2) + sqrt(3)*xi**4*(l2 - l3)*(-l1 + 2*l2 - l3)*(2*l1 - l2 - l3)/(c4*r**4) - sqrt(3)*xi**4*(l2 - l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)/(c4*r**4) + sqrt(3)*xi**4*(2*l1 - l2 - l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)/(c4*r**4) - sqrt(3)*xi**6*(l2 - l3)*(-2*l1 + 4*l2 - 2*l3)*(2*l1 - l2 - l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)/(c3*r**6) + sqrt(3)*xi**6*(l2 - l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**2/(c3*r**6) - sqrt(3)*xi**6*(2*l1 - l2 - l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**2/(c3*r**6) + sqrt(3)*xi**8*(l2 - l3)*(-3*l1 + 6*l2 - 3*l3)*(2*l1 - l2 - l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**2/(c2*r**8) - sqrt(3)*xi**8*(l2 - l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**3/(c2*r**8) + sqrt(3)*xi**8*(2*l1 - l2 - l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**3/(c2*r**8) + sqrt(3)*xi**10*(l2 - l3)*(-4*l1 + 8*l2 - 4*l3)*(2*l1 - l2 - l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**3/(c1*r**10) - sqrt(3)*xi**10*(l2 - l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**4/(c1*r**10) + sqrt(3)*xi**10*(2*l1 - l2 - l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**4/(c1*r**10), -xi**2*(2*l2 - 2*l3)/(6*r**2) + xi**4*(l2 - l3)**2*(-l1 + 2*l2 - l3)/(c13*r**4) + xi**4*(2*l2 - 2*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)/(c13*r**4) - xi**6*(l2 - l3)**2*(-2*l1 + 4*l2 - 2*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)/(c12*r**6) - xi**6*(2*l2 - 2*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**2/(c12*r**6) + xi**8*(l2 - l3)**2*(-3*l1 + 6*l2 - 3*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**2/(c11*r**8) + xi**8*(2*l2 - 2*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**3/(c11*r**8) - xi**10*(l2 - l3)**2*(-4*l1 + 8*l2 - 4*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**3/(c10*r**10) - xi**10*(2*l2 - 2*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**4/(c10*r**10), -sqrt(3)*xi/(3*r) + 2*sqrt(3)*xi**3*(l2 - l3)*(-l1 + 2*l2 - l3)/(c9*r**3) + 2*sqrt(3)*xi**3*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)/(c9*r**3) - 2*sqrt(3)*xi**5*(l2 - l3)*(-2*l1 + 4*l2 - 2*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)/(c8*r**5) - 2*sqrt(3)*xi**5*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**2/(c8*r**5) + 4*sqrt(3)*xi**7*(l2 - l3)*(-3*l1 + 6*l2 - 3*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**2/(c7*r**7) + 4*sqrt(3)*xi**7*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**3/(c7*r**7) - 2*sqrt(3)*xi**9*(l2 - l3)*(-4*l1 + 8*l2 - 4*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**3/(c6*r**9) - 2*sqrt(3)*xi**9*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**4/(c6*r**9)], [-xi/(3*r) - xi**3*(-l1 + 2*l2 - l3)*(4*l1 - 2*l2 - 2*l3)/(c9*r**3) + 2*xi**3*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)/(c9*r**3) + xi**5*(-2*l1 + 4*l2 - 2*l3)*(4*l1 - 2*l2 - 2*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)/(c8*r**5) - 2*xi**5*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**2/(c8*r**5) - xi**7*(-3*l1 + 6*l2 - 3*l3)*(8*l1 - 4*l2 - 4*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**2/(c7*r**7) + 4*xi**7*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**3/(c7*r**7) + xi**9*(-4*l1 + 8*l2 - 4*l3)*(4*l1 - 2*l2 - 2*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**3/(c6*r**9) - 2*xi**9*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**4/(c6*r**9), sqrt(3)*xi/(3*r) - 2*sqrt(3)*xi**3*(l2 - l3)*(-l1 + 2*l2 - l3)/(c9*r**3) - 2*sqrt(3)*xi**3*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)/(c9*r**3) + 2*sqrt(3)*xi**5*(l2 - l3)*(-2*l1 + 4*l2 - 2*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)/(c8*r**5) + 2*sqrt(3)*xi**5*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**2/(c8*r**5) - 4*sqrt(3)*xi**7*(l2 - l3)*(-3*l1 + 6*l2 - 3*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**2/(c7*r**7) - 4*sqrt(3)*xi**7*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**3/(c7*r**7) + 2*sqrt(3)*xi**9*(l2 - l3)*(-4*l1 + 8*l2 - 4*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**3/(c6*r**9) + 2*sqrt(3)*xi**9*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**4/(c6*r**9), -2*xi**2*(-l1 + 2*l2 - l3)/(9*r**2) - 4*xi**6*(-3*l1 + 6*l2 - 3*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**2/(c3*r**6) + 2*xi**8*(-4*l1 + 8*l2 - 4*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**3/(c15*r**8) + 2*xi**4*(-2*l1 + 4*l2 - 2*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)/(c14*r**4) - 4*xi**10*(-5*l1 + 10*l2 - 5*l3)*(l1**2 - l1*l2 - l1*l3 + l2**2 - l2*l3 + l3**2)**4/(c1*r**10)]])

```python
dRdl3 = sy.diff(R, l3)
dRdl3
```

$\displaystyle \left[\begin{matrix}- \frac{\xi^{2} \left(- 4 l_{1} + 2 l_{2} + 2 l_{3}\right)}{c_{5} r^{2}} + \frac{\xi^{4} \left(- 4 l_{1} + 2 l_{2} + 2 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{4} r^{4}} + \frac{\xi^{4} \left(- l_{1} - l_{2} + 2 l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right)^{2}}{c_{4} r^{4}} - \frac{\xi^{6} \left(- 4 l_{1} + 2 l_{2} + 2 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{3} r^{6}} - \frac{\xi^{6} \left(- 2 l_{1} - 2 l_{2} + 4 l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right)^{2} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{3} r^{6}} + \frac{\xi^{8} \left(- 4 l_{1} + 2 l_{2} + 2 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{1} r^{8}} + \frac{\xi^{8} \left(- 3 l_{1} - 3 l_{2} + 6 l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right)^{2} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{1} r^{8}} - \frac{\xi^{10} \left(- 4 l_{1} - 4 l_{2} + 8 l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right)^{2} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{1} r^{10}} - \frac{\xi^{10} \left(- 4 l_{1} + 2 l_{2} + 2 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{4}}{c_{1} r^{10}} & \frac{\sqrt{3} \xi^{2} \left(l_{2} - l_{3}\right)}{c_{5} r^{2}} + \frac{\sqrt{3} \xi^{2} \left(2 l_{1} - l_{2} - l_{3}\right)}{c_{5} r^{2}} + \frac{\sqrt{3} \xi^{4} \left(l_{2} - l_{3}\right) \left(- l_{1} - l_{2} + 2 l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right)}{c_{4} r^{4}} - \frac{\sqrt{3} \xi^{4} \left(l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{4} r^{4}} - \frac{\sqrt{3} \xi^{4} \left(2 l_{1} - l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{4} r^{4}} - \frac{\sqrt{3} \xi^{6} \left(l_{2} - l_{3}\right) \left(- 2 l_{1} - 2 l_{2} + 4 l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{3} r^{6}} + \frac{\sqrt{3} \xi^{6} \left(l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{3} r^{6}} + \frac{\sqrt{3} \xi^{6} \left(2 l_{1} - l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{3} r^{6}} + \frac{\sqrt{3} \xi^{8} \left(l_{2} - l_{3}\right) \left(- 3 l_{1} - 3 l_{2} + 6 l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{2} r^{8}} - \frac{\sqrt{3} \xi^{8} \left(l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{2} r^{8}} - \frac{\sqrt{3} \xi^{8} \left(2 l_{1} - l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{2} r^{8}} + \frac{\sqrt{3} \xi^{10} \left(l_{2} - l_{3}\right) \left(- 4 l_{1} - 4 l_{2} + 8 l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{1} r^{10}} - \frac{\sqrt{3} \xi^{10} \left(l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{4}}{c_{1} r^{10}} - \frac{\sqrt{3} \xi^{10} \left(2 l_{1} - l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{4}}{c_{1} r^{10}} & \frac{\xi}{3 r} + \frac{\xi^{3} \left(- l_{1} - l_{2} + 2 l_{3}\right) \left(4 l_{1} - 2 l_{2} - 2 l_{3}\right)}{c_{9} r^{3}} - \frac{2 \xi^{3} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{9} r^{3}} - \frac{\xi^{5} \left(- 2 l_{1} - 2 l_{2} + 4 l_{3}\right) \left(4 l_{1} - 2 l_{2} - 2 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{8} r^{5}} + \frac{2 \xi^{5} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{8} r^{5}} + \frac{\xi^{7} \left(- 3 l_{1} - 3 l_{2} + 6 l_{3}\right) \left(8 l_{1} - 4 l_{2} - 4 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{7} r^{7}} - \frac{4 \xi^{7} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{7} r^{7}} - \frac{\xi^{9} \left(- 4 l_{1} - 4 l_{2} + 8 l_{3}\right) \left(4 l_{1} - 2 l_{2} - 2 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{6} r^{9}} + \frac{2 \xi^{9} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{4}}{c_{6} r^{9}}\\\frac{\sqrt{3} \xi^{2} \left(l_{2} - l_{3}\right)}{c_{5} r^{2}} + \frac{\sqrt{3} \xi^{2} \left(2 l_{1} - l_{2} - l_{3}\right)}{c_{5} r^{2}} + \frac{\sqrt{3} \xi^{4} \left(l_{2} - l_{3}\right) \left(- l_{1} - l_{2} + 2 l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right)}{c_{4} r^{4}} - \frac{\sqrt{3} \xi^{4} \left(l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{4} r^{4}} - \frac{\sqrt{3} \xi^{4} \left(2 l_{1} - l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{4} r^{4}} - \frac{\sqrt{3} \xi^{6} \left(l_{2} - l_{3}\right) \left(- 2 l_{1} - 2 l_{2} + 4 l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{3} r^{6}} + \frac{\sqrt{3} \xi^{6} \left(l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{3} r^{6}} + \frac{\sqrt{3} \xi^{6} \left(2 l_{1} - l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{3} r^{6}} + \frac{\sqrt{3} \xi^{8} \left(l_{2} - l_{3}\right) \left(- 3 l_{1} - 3 l_{2} + 6 l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{2} r^{8}} - \frac{\sqrt{3} \xi^{8} \left(l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{2} r^{8}} - \frac{\sqrt{3} \xi^{8} \left(2 l_{1} - l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{2} r^{8}} + \frac{\sqrt{3} \xi^{10} \left(l_{2} - l_{3}\right) \left(- 4 l_{1} - 4 l_{2} + 8 l_{3}\right) \left(2 l_{1} - l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{1} r^{10}} - \frac{\sqrt{3} \xi^{10} \left(l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{4}}{c_{1} r^{10}} - \frac{\sqrt{3} \xi^{10} \left(2 l_{1} - l_{2} - l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{4}}{c_{1} r^{10}} & - \frac{\xi^{2} \left(- 2 l_{2} + 2 l_{3}\right)}{6 r^{2}} + \frac{\xi^{4} \left(- 2 l_{2} + 2 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{13} r^{4}} + \frac{\xi^{4} \left(l_{2} - l_{3}\right)^{2} \left(- l_{1} - l_{2} + 2 l_{3}\right)}{c_{13} r^{4}} - \frac{\xi^{6} \left(- 2 l_{2} + 2 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{12} r^{6}} - \frac{\xi^{6} \left(l_{2} - l_{3}\right)^{2} \left(- 2 l_{1} - 2 l_{2} + 4 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{12} r^{6}} + \frac{\xi^{8} \left(- 2 l_{2} + 2 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{11} r^{8}} + \frac{\xi^{8} \left(l_{2} - l_{3}\right)^{2} \left(- 3 l_{1} - 3 l_{2} + 6 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{11} r^{8}} - \frac{\xi^{10} \left(- 2 l_{2} + 2 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{4}}{c_{10} r^{10}} - \frac{\xi^{10} \left(l_{2} - l_{3}\right)^{2} \left(- 4 l_{1} - 4 l_{2} + 8 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{10} r^{10}} & \frac{\sqrt{3} \xi}{3 r} + \frac{2 \sqrt{3} \xi^{3} \left(l_{2} - l_{3}\right) \left(- l_{1} - l_{2} + 2 l_{3}\right)}{c_{9} r^{3}} - \frac{2 \sqrt{3} \xi^{3} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{9} r^{3}} - \frac{2 \sqrt{3} \xi^{5} \left(l_{2} - l_{3}\right) \left(- 2 l_{1} - 2 l_{2} + 4 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{8} r^{5}} + \frac{2 \sqrt{3} \xi^{5} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{8} r^{5}} + \frac{4 \sqrt{3} \xi^{7} \left(l_{2} - l_{3}\right) \left(- 3 l_{1} - 3 l_{2} + 6 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{7} r^{7}} - \frac{4 \sqrt{3} \xi^{7} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{7} r^{7}} - \frac{2 \sqrt{3} \xi^{9} \left(l_{2} - l_{3}\right) \left(- 4 l_{1} - 4 l_{2} + 8 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{6} r^{9}} + \frac{2 \sqrt{3} \xi^{9} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{4}}{c_{6} r^{9}}\\- \frac{\xi}{3 r} - \frac{\xi^{3} \left(- l_{1} - l_{2} + 2 l_{3}\right) \left(4 l_{1} - 2 l_{2} - 2 l_{3}\right)}{c_{9} r^{3}} + \frac{2 \xi^{3} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{9} r^{3}} + \frac{\xi^{5} \left(- 2 l_{1} - 2 l_{2} + 4 l_{3}\right) \left(4 l_{1} - 2 l_{2} - 2 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{8} r^{5}} - \frac{2 \xi^{5} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{8} r^{5}} - \frac{\xi^{7} \left(- 3 l_{1} - 3 l_{2} + 6 l_{3}\right) \left(8 l_{1} - 4 l_{2} - 4 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{7} r^{7}} + \frac{4 \xi^{7} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{7} r^{7}} + \frac{\xi^{9} \left(- 4 l_{1} - 4 l_{2} + 8 l_{3}\right) \left(4 l_{1} - 2 l_{2} - 2 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{6} r^{9}} - \frac{2 \xi^{9} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{4}}{c_{6} r^{9}} & - \frac{\sqrt{3} \xi}{3 r} - \frac{2 \sqrt{3} \xi^{3} \left(l_{2} - l_{3}\right) \left(- l_{1} - l_{2} + 2 l_{3}\right)}{c_{9} r^{3}} + \frac{2 \sqrt{3} \xi^{3} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{9} r^{3}} + \frac{2 \sqrt{3} \xi^{5} \left(l_{2} - l_{3}\right) \left(- 2 l_{1} - 2 l_{2} + 4 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{8} r^{5}} - \frac{2 \sqrt{3} \xi^{5} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{8} r^{5}} - \frac{4 \sqrt{3} \xi^{7} \left(l_{2} - l_{3}\right) \left(- 3 l_{1} - 3 l_{2} + 6 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{7} r^{7}} + \frac{4 \sqrt{3} \xi^{7} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{7} r^{7}} + \frac{2 \sqrt{3} \xi^{9} \left(l_{2} - l_{3}\right) \left(- 4 l_{1} - 4 l_{2} + 8 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{6} r^{9}} - \frac{2 \sqrt{3} \xi^{9} \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{4}}{c_{6} r^{9}} & - \frac{2 \xi^{2} \left(- l_{1} - l_{2} + 2 l_{3}\right)}{9 r^{2}} - \frac{4 \xi^{6} \left(- 3 l_{1} - 3 l_{2} + 6 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{2}}{c_{3} r^{6}} + \frac{2 \xi^{8} \left(- 4 l_{1} - 4 l_{2} + 8 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{3}}{c_{15} r^{8}} + \frac{2 \xi^{4} \left(- 2 l_{1} - 2 l_{2} + 4 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)}{c_{14} r^{4}} - \frac{4 \xi^{10} \left(- 5 l_{1} - 5 l_{2} + 10 l_{3}\right) \left(l_{1}^{2} - l_{1} l_{2} - l_{1} l_{3} + l_{2}^{2} - l_{2} l_{3} + l_{3}^{2}\right)^{4}}{c_{1} r^{10}}\end{matrix}\right]$


Computational Seismology

Spectral Element Method - 1D Elastic Wave Equation, Heterogeneous case

Seismo-Live: http://seismo-live.org

##### Authors:
* David Vargas ([@dvargas](https://github.com/davofis))
* Heiner Igel ([@heinerigel](https://github.com/heinerigel))

## Basic Equations

The numerical description of 1D-elastic waves propagating in a heterogeneous media is a natural extension of the homogeneous case. From an algorithmic point of view, now we allow both mass, and stiffness matrices to be initialised separately for each element. In constrast with the homogeneous case, elastic parameters $\lambda$ and $\mu$ may vary at each collocation point.

From a theoretical point of view, we basically follow the same strategy developed in the homogeneous case. The numerical solution for the 1D elastic wave equation

\begin{equation}
\rho(x) \partial_t^2 u(x,t) = \partial_x (\mu(x) \partial_x u(x,t)) + f(x,t),
\end{equation}

using the spectral element method is done after a series of steps summarized as follow:

1) The wave equation is written into its Weak form

2) Apply stress Free Boundary Condition after integration by parts

3) Approximate the wave field as a linear combination of some basis

\begin{equation}
u(x,t) \ \approx \ \overline{u}(x,t) \ = \ \sum_{i=1}^{n} u_i(t) \ \varphi_i(x)
\end{equation}

4) Use the same basis functions in $u(x, t)$ as test functions in the weak form, the so call Galerkin principle.

6) The continuous weak form is written as a system of linear equations by considering the approximated displacement field.

\begin{equation}
\mathbf{M}^T\partial_t^2 \mathbf{u} + \mathbf{K}^T\mathbf{u} = \mathbf{f}
\end{equation}

7) Time extrapolation with centered finite differences scheme

\begin{equation}
\mathbf{u}(t + dt) = dt^2 (\mathbf{M}^T)^{-1}[\mathbf{f} - \mathbf{K}^T\mathbf{u}] + 2\mathbf{u} - \mathbf{u}(t-dt).
\end{equation}

where $\mathbf{M}$ is known as the mass matrix, and $\mathbf{K}$ the stiffness matrix.

The above solution is exactly the same presented for the classic finite-element method. Now we introduce appropriated basis functions and integration scheme to efficiently solve the system of matrices.

#### Interpolation with Lagrange Polynomials
At the elemental level (see section 7.4), we introduce as interpolating functions the Lagrange polynomials and use $\xi$ as the space variable representing our elemental domain:

\begin{equation}
\varphi_i \ \rightarrow \ \ell_i^{(N)} (\xi) \ := \ \prod_{j \neq i}^{N+1} \frac{\xi - \xi_j}{\xi_i-\xi_j}, \qquad   i,j = 1, 2, \dotsc , N + 1
\end{equation}

#### Numerical Integration
The integral of a continuous function $f(x)$ can be calculated after replacing $f(x)$ by a polynomial approximation that can be integrated analytically. As interpolating functions we use again the Lagrange polynomials and
obtain Gauss-Lobatto-Legendre quadrature. Here, the GLL points are used to perform the integral.

\begin{equation}
\int_{-1}^1 f(x) \ dx \approx \int _{-1}^1 P_N(x) dx = \sum_{i=1}^{N+1}
 w_i f(x_i)
\end{equation}

```python
# Import all necessary libraries, this is a configuration step for the exercise.
# Please run it before the simulation code!
import numpy as np
import matplotlib.pyplot as plt

from gll import gll
from lagrange1st import lagrange1st
from ricker import ricker

# Show the plots in the Notebook.
plt.switch_backend("nbagg")
```

### 1. Initialization of setup

```python
# Initialization of setup
# ---------------------------------------------------------------
nt    = 10000         # number of time steps
xmax  = 8000.         # Length of domain [m]
N     = 3             # Order of Lagrange polynomials
ne    = 250           # Number of elements
Tdom  = .2            # Dominant period of Ricker source wavelet
iplot = 20            # Plotting each iplot snapshot
vs    = 2500.         # S velocity [m/s]
rho   = 2000          # Density [kg/m^3]

# variables for elemental matrices
Me = np.zeros(N+1, dtype =  float)
Ke = np.zeros((N+1, N+1), dtype =  float)
# ----------------------------------------------------------------

# Initialization of GLL points integration weights
[xi, w] = gll(N)    # xi, N+1 coordinates [-1 1] of GLL points
                    # w Integration weights at GLL locations
# Space domain
le = xmax/ne        # Length of elements
# Vector with GLL points
k = 0
xg = np.zeros((N*ne)+1)
xg[k] = 0
for i in range(1,ne+1):
    for j in range(0,N):
        k = k+1
        xg[k] = (i-1)*le + .5*(xi[j+1]+1)*le

# ---------------------------------------------------------------
dxmin = min(np.diff(xg))
eps = 0.1           # Courant value
dt = eps*dxmin/vs   # Global time step

# Mapping - Jacobian
J = le/2
Ji = 1/J    # Inverse Jacobian

# 1st derivative of Lagrange polynomials
l1d = lagrange1st(N)   # Array with GLL as columns for each N+1 polynomial
```

### 2. Low velocity zone
The introduction of an specific velocity model is done after allowing space-dependent elastic parameters. i.e.

\begin{equation}
\mu(x) = \rho(x) v_s(x)
\end{equation}

#### Exercise 1
Introduce a low-velocity zone (-40%) at the center of the model spanning 50 elements. Then, visualize your model. Additionally, you can try different velocity and density models by defining new python methods.

```python
# Elastic parameters, Low velocity zone(-40%)
# ----------------------------------------------------------------
el_span = 50                     # Number of elements spanning the Low velocity zone
percent = 0.4                    # percentage of velocity reduction
a = el_span*N + 1                # with of the fault zone in grid points
b = int(np.floor((N*ne +1)/2))   # half of the space domain.

vs  = vs * np.ones((N*ne +1))
rho = rho * np.ones((N*ne +1))

vs[b-int(a/2):b+int(a/2)] = max(vs) * percent
mu  = rho * vs**2                  # Shear modulus mu

# ----------------------------------------------------------------
# Plot velocity model, Low velocity zone(-30%)
# ----------------------------------------------------------------
plt.plot(xg, vs, lw = 1.5)
plt.title('Velocity model',fontsize=16)
plt.ylabel('Velocity $(m/s)$',fontsize=16)
plt.xlabel('space $(m)$',fontsize=16)
plt.xlim((0,xmax))
plt.ylim((0,max(vs)+50))
plt.tight_layout()
plt.show()
```

### 3. The Mass Matrix
Now we initialize the mass and stiffness matrices. In general, the mass matrix at the elemental level is given

\begin{equation}
M_{ji}^e \ = \ w_j  \ \rho (\xi)  \ \frac{\mathrm{d}x}{\mathrm{d}\xi} \delta_{ij} \vert_ {\xi = \xi_j}
\end{equation}

#### Exercise 2
Implements the mass matrix at each element using the integration weights at GLL locations $w$, the jacobian $J$, and density $\rho$. Then, perform the global assembly of the mass matrix, compute its inverse, and display the inverse mass matrix to visually inspect how it looks like.

```python
# Global Mass matrix
# ---------------------------------------------------------------
k = -1
m = -1
ng = (ne-1)*N + N + 1
M = np.zeros(2*ng)
for i in range(1, ne+1):
    # ------------------------------------
    # Elemental Mass matrix
    # ------------------------------------
    for l in range(0, N+1):
        m += 1
        Me[l] = rho[m] * w[l] * J    #stored as a vector since it's diagonal
    m -= 1
    # ------------------------------------
    for j in range(0, N+1):
        k = k + 1
        if i>1:
            if j==0:
                k = k - 1
        M[k] = M[k] + Me[j]

# Inverse matrix of M
# ---------------------------------------------------------------
Minv = np.identity(ng)
for i in range(0,ng):
    Minv[i,i] = 1./M[i]

# ---------------------------------------------------------------
# Display inverse mass matrix inv(M)
# ---------------------------------------------------------------
plt.figure()
plt.imshow(Minv)
plt.title('Mass Matrix $\mathbf{M}$')
plt.axis("off")
plt.tight_layout()
plt.show()
```

### 4. The Stiffness matrix
On the other hand, the general form of the stiffness matrix at the elemtal level is

\begin{equation}
K_{ji}^e \ = \ \sum_{k = 1}^{N+1} w_k \mu (\xi) \partial_\xi \ell_j (\xi) \partial_\xi \ell_i (\xi) \left(\frac{\mathrm{d}\xi}{\mathrm{d}x} \right)^2 \frac{\mathrm{d}x}{\mathrm{d}\xi} \vert_{\xi = \xi_k}
\end{equation}

#### Exercise 3
Implements the stiffness matrix at each element using the integration weights at GLL locations $w$, the jacobian $J$, and shear stress $\mu$. Then, perform the global assembly of the mass matrix and display the matrix to visually inspect how it looks like.

```python
# Global Stiffness Matrix
# ---------------------------------------------------------------
K = np.zeros([ng, ng])
xe = 0

for e in range(1, ne + 1):
    i0 = (e - 1)*N + 1
    j0 = i0
    # ------------------------------------
    # Elemental Stiffness Matrix
    # ------------------------------------
    for i in range(-1, N):
        for j in range(-1, N):
            sum = 0
            for k in range(-1, N):
                sum = sum + mu[k+1+xe] * w[k+1] * Ji**2 * J * l1d[i+1,k+1] * l1d[j+1,k+1]
            Ke[i+1, j+1] = sum
    xe += N

    for i in range(-1,N):
        for j in range(-1, N):
            K[i0+i, j0+j] += Ke[i+1, j+1]

# ---------------------------------------------------------------
# Display stiffness matrix K
# ---------------------------------------------------------------
plt.figure()
plt.imshow(K)
plt.title('Stiffness Matrix $\mathbf{K}$')
plt.axis("off")

plt.tight_layout()
plt.show()
```

### 5. Finite element solution

Finally we implement the spectral element solution using the computed mass $M$ and stiffness $K$ matrices together with a finite differences extrapolation scheme

\begin{equation}
\mathbf{u}(t + dt) = dt^2 (\mathbf{M}^T)^{-1}[\mathbf{f} - \mathbf{K}^T\mathbf{u}] + 2\mathbf{u} - \mathbf{u}(t-dt).
\end{equation}

```python
# SE Solution, Time extrapolation
# ---------------------------------------------------------------

# initialize source time function and force vector f
src  = ricker(dt,Tdom)
isrc = int(np.floor(ng/2))   # Source location

# Initialization of solution vectors
u = np.zeros(ng)
uold = u
unew = u
f = u

# Initialize animated plot
# ---------------------------------------------------------------
plt.figure(figsize=(10,6))

# ploting low velocity zone
half = np.floor(xmax/2)
plt.axvspan(half - el_span/2*le,
            half + el_span/2*le,
            alpha=0.2, facecolor='b')
plt.title('SEM 1D Animation')
plt.xlabel(' x (m)')
plt.ylabel(' Amplitude ')
font = {'family': 'serif',
        'color':  'black',
        'weight': 'normal',
        'size': 16,
        }

lines = plt.plot(xg, u, lw=1.5)
plt.title('SEM 1D Animation   $v_{min} = %s v_{max}$' %percent, size=16)
plt.xlabel(' x (m)')
plt.ylabel(' Displacement ')

plt.ion() # set interective mode
plt.show()

# ---------------------------------------------------------------
# Time extrapolation
# ---------------------------------------------------------------
x_t = []
for it in range(nt):
    # Source initialization
    f = np.zeros(ng)
    if it < len(src):
        f[isrc-1] = src[it-1]

    # Time extrapolation
    unew = dt**2 * Minv @ (f - K @ u) + 2 * u - uold
    uold, u = u, unew

    # Solution in space-time
    x_t.append(u)

    # --------------------------------------
    # Animation plot. Display solution
    if not it % iplot:
        for l in lines:
            l.remove()
            del l
        # --------------------------------------
        # Display lines
        lines = plt.plot(xg, u, color="black", lw = 1.5)
        plt.xlim((0,xmax))
        plt.gcf().canvas.draw()
```

### 6. Displaying the wave-field

```python
# Solution in space-time
x_t = np.asanyarray(x_t)

# Initialize plot
plt.figure()
plt.subplot(1,1,1)
plt.imshow(x_t, cmap='hot', aspect='auto',
          extent =[0, xmax, nt*dt, 0])
plt.title('u(x,t) Wavefield')
plt.ylabel('Time [s]')
plt.xlabel('Space [m]')
plt.show()
```