Sympy to calculate partial derivatives
======================================


```
from sympy import Symbol, symbols, Matrix, diff, expand
```


```
x, y = symbols('x,y')
```


```
p0,p1,p2,p3,p4,p5,p6,p7 = symbols('p0,p1,p2,p3,p4,p5,p6,p7')
```


```
H = Matrix([(p0+1,p3,p6), (p1,p4+1,p7), (p2,p5,1.0)])
P = Matrix([(x),(y),(1.0)])
H
```




    [p0 + 1,     p3,  p6]
    [    p1, p4 + 1,  p7]
    [    p2,     p5, 1.0]




```
equations = H*P
```


```
equations
```




    [p3*y + 1.0*p6 + x*(p0 + 1)]
    [p1*x + 1.0*p7 + y*(p4 + 1)]
    [         p2*x + p5*y + 1.0]




```
xequation = equations[0] / equations[2]
```


```
yequation = equations[1] / equations[2]
```

Formulate equations for partial derivatives:


```
for var in (p0,p1,p2,p3,p4,p5,p6,p7):
    eq = diff(xequation, var)
    print '{}: {}'.format(var, eq)
```

    p0: x/(p2*x + p5*y + 1.0)
    p1: 0
    p2: -x*(p3*y + 1.0*p6 + x*(p0 + 1))/(p2*x + p5*y + 1.0)**2
    p3: y/(p2*x + p5*y + 1.0)
    p4: 0
    p5: -y*(p3*y + 1.0*p6 + x*(p0 + 1))/(p2*x + p5*y + 1.0)**2
    p6: 1.0/(p2*x + p5*y + 1.0)
    p7: 0



```
for var in (p0,p1,p2,p3,p4,p5,p6,p7):
    eq = diff(yequation, var)
    print '{}: {}'.format(var, eq)
```

    p0: 0
    p1: x/(p2*x + p5*y + 1.0)
    p2: -x*(p1*x + 1.0*p7 + y*(p4 + 1))/(p2*x + p5*y + 1.0)**2
    p3: 0
    p4: y/(p2*x + p5*y + 1.0)
    p5: -y*(p1*x + 1.0*p7 + y*(p4 + 1))/(p2*x + p5*y + 1.0)**2
    p6: 0
    p7: 1.0/(p2*x + p5*y + 1.0)



```

```

3bb37aba0478e4128529b963236052d10fc169e0
ipynb
Jupyter Notebook
notebooks/math.ipynb
pyimreg/imreg
37e03f5c1cbab77bd686cddaf8c6241c9e3d8dc6
Apache-2.0
2015-03-16T19:22:37.000Z
2021-03-17T03:43:42.000Z
notebooks/math.ipynb
pyimreg/imreg
37e03f5c1cbab77bd686cddaf8c6241c9e3d8dc6
Apache-2.0
notebooks/math.ipynb
pyimreg/imreg
37e03f5c1cbab77bd686cddaf8c6241c9e3d8dc6
Apache-2.0
2015-12-01T06:05:35.000Z
2021-01-03T22:24:42.000Z
Qwen/Qwen-72B
1. YES
2. YES