```python
import numpy as np
```

Notation see [here](https://www.overleaf.com/project/5eb163d1d04a61000199ae5f).


A _deformation_ transformes lattice vectors ${\bf a}_i$ into new lattice vectors ${\bf a}_i'$:

$$
\begin{align}
    A' =     
    \begin{pmatrix}
        -~ {\bf a'}^1 ~- \\
        -~ {\bf a'}^2 ~- \\
        \vdots \\
    \end{pmatrix}
    =     
    D
    \begin{pmatrix}
        -~ {\bf a}^1 ~- \\
        -~ {\bf a}^2 ~- \\
        \vdots \\
    \end{pmatrix}
    = D A~.
\end{align}
$$

Write  in shape $Ax = B$ by transposing:
$$
\begin{align}
    (A')^{\rm t} = A^{\rm t} D^{\rm t}
\end{align}
$$

so that $D$ can be obtained by `D = np.linalg.solve(A1.T, A2.T).T`.


```python
def get_deformation(cell1, cell2):
    """Compute the matrix that deforms cell1 into cell2"""
    return np.linalg.solve(cell1.T, cell2.T).T
```


```python
# Example

A1 = np.array([[0, 1, 1], [1, 0, 1], [1, 1, 0]])
A2 = np.array([[0, 1, 2], [1, 0, 1], [1, 1, 0]])
```


```python
# verify
D = get_deformation(A1, A2)
D
```




    array([[ 1.5,  0.5, -0.5],
           [ 0. ,  1. , -0. ],
           [ 0. ,  0. ,  1. ]])




```python
np.linalg.norm(D @ A1 - A2)
```




    0.0




```python

```

9aa42de18b2b2f9ca81cd423b995d0945bf69d8e
ipynb
Jupyter Notebook
physics/strain/deformation.ipynb
flokno/python_recipes
a09da65528ce3a2f1fd884aea361275b9aab0c15
0BSD
2020-05-06T14:38:16.000Z
2022-01-05T09:43:04.000Z
physics/strain/deformation.ipynb
flokno/python_recipes
a09da65528ce3a2f1fd884aea361275b9aab0c15
0BSD
physics/strain/deformation.ipynb
flokno/python_recipes
a09da65528ce3a2f1fd884aea361275b9aab0c15
0BSD
Qwen/Qwen-72B
1. YES
2. YES