## 2020年3月31日火曜日

### 数学 - Python - 解析学 - 多変数の関数 - 多変数の関数 - 偏微分 - 偏導関数、積、累乗、三角関数(正弦、余弦)、逆正弦関数、指数関数

1. $\begin{array}{l}\frac{\partial f}{\partial x}\\ =\frac{\partial }{\partial x}\left(xy+z\right)\\ =y\\ \frac{\partial }{\partial y}\left(xy+z\right)=x\\ \frac{\partial }{\partial z}\left(xy+z\right)=1\end{array}$

2. $\begin{array}{l}\frac{\partial }{\partial x}\left({x}^{2}{y}^{5}+1\right)=2x{y}^{5}\\ \frac{\partial f}{\partial y}=5{x}^{2}{y}^{4}\\ \frac{\partial f}{\partial z}=0\end{array}$

3. $\begin{array}{l}\frac{\partial }{\partial x}\left(\mathrm{sin}\left(xy\right)+\mathrm{cos}z\right)\\ =\left(\mathrm{cos}\left(xy\right)\right)y\\ \frac{\partial f}{\partial y}=\left(\mathrm{cos}\left(xy\right)\right)x\\ \frac{\partial f}{\partial z}=-\mathrm{sin}z\end{array}$

4. $\begin{array}{l}\frac{\partial }{\partial x}\mathrm{cos}\left(xy\right)=-\left(\mathrm{sin}xy\right)y\\ \frac{\partial f}{\partial y}=-\left(\mathrm{sin}xy\right)x\\ \frac{\partial f}{\partial z}=0\end{array}$

5. $\begin{array}{l}\frac{\partial }{\partial x}\mathrm{sin}\left(xyz\right)=\left(\mathrm{cos}\left(xyz\right)\right)yz\\ \frac{\partial f}{\partial y}=\left(\mathrm{cos}\left(xyz\right)\right)xz\\ \frac{\partial f}{\partial z}=\left(\mathrm{cos}\left(xyz\right)\right)xy\end{array}$

6. $\begin{array}{l}\frac{\partial }{\partial x}{e}^{xyz}={e}^{xyz}yz\\ \frac{\partial f}{\partial y}={e}^{xyz}xz\\ \frac{\partial f}{\partial z}={e}^{xyz}xy\end{array}$

7. $\begin{array}{l}\frac{\partial }{\partial x}\left({x}^{2}\mathrm{sin}\left(yz\right)\right)=2x\mathrm{sin}\left(yz\right)\\ \frac{\partial f}{\partial y}={x}^{2}\left(\mathrm{cos}\left(yz\right)\right)z\\ \frac{\partial f}{\partial z}={x}^{2}\left(\mathrm{cos}\left(yz\right)\right)y\end{array}$

8. $\begin{array}{l}\frac{\partial }{\partial x}\left(xyz\right)=yz\\ \frac{\partial f}{\partial y}=xz\\ \frac{\partial f}{\partial z}=xy\end{array}$

9. $\begin{array}{l}\frac{\partial }{\partial x}\left(xz+yz+xy\right)=z+y\\ \frac{\partial f}{\partial y}=z+x\\ \frac{\partial f}{\partial z}=x+y\end{array}$

10. $\begin{array}{l}\frac{\partial }{\partial x}\left(x\mathrm{cos}\left(y-3z\right)+\mathrm{arcsin}\left(xy\right)\right)\\ =\mathrm{cos}\left(y-3z\right)+\frac{y}{\sqrt{1-{x}^{2}{y}^{2}}}\\ \frac{\partial f}{\partial y}=x\left(-\mathrm{sin}\left(y-3z\right)\right)+\frac{x}{\sqrt{1-{x}^{2}{y}^{2}}}\\ \frac{\partial f}{\partial z}=x\left(-\mathrm{sin}\left(y-3z\right)\right)\left(-3\right)\end{array}$

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import symbols, plot, sin, cos, exp, asin, Derivative, sqrt
from sympy.plotting import plot3d

print('1, 2, 3, 4, 5, 6, 7, 8, 9, 10.')

x, y, z = symbols('x, y, z', real=True)
fs = [x * y + z,
x ** 2 * y ** 5 + 1,
sin(x * y) + cos(z),
cos(x * y),
sin(x * y * z),
exp(x * y * z),
x ** 2 * sin(y * z),
x * y * z,
x * z + y * z + x * y,
x * cos(y - 3 * z) + asin(x * y)]

fxyzs = [(y, x, 1),
(2 * x * y ** 5, 5 * x ** 2 * y ** 4, 0),
(cos(x * y) * y, cos(x * y) * x, -sin(z)),
(-sin(x * y) * y, -sin(x * y) * x, 0),
(cos(x * y * z) * y * z,
cos(x * y * z) * x * z,
cos(x * y * z) * x * y),
(exp(x * y * z) * y * z,
exp(x * y * z) * x * z,
exp(x * y * z) * x * y),
(2 * x * sin(y * z),
x ** 2 * cos(y * z) * z,
x ** 2 * cos(y * z) * y),
(y * z, x * z, x * y),
(z + y, z + x, x + y),
(cos(y - 3 * z) + y / sqrt(1 - x ** 2 * y ** 2),
x * (- sin(y - 3 * z)) + x / sqrt(1 - x ** 2 * y ** 2),
x * (-sin(y - 3 * z)) * (-3))]

class TestPartialDerivative(TestCase):
def test(self):
for f, fxyz in zip(fs, fxyzs):
for fo, o in zip(fxyz, [x, y, z]):
self.assertEqual(
Derivative(f, o, 1).doit(),
fo)

for i, f in enumerate(fs, 1):
p = plot3d(f.subs({z: 1}),
show=False)
p.save(f'sample{i}.png')

p.show()

if __name__ == "__main__":
main()


% ./sample1.py -v
1, 2, 3, 4, 5, 6, 7, 8, 9, 10.
test (__main__.TestPartialDerivative) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.034s

OK
%