2018年2月4日日曜日

数学 - Python - 解析学 - 多変数の関数 - 高次偏導関数、テイラーの定理(指数関数、グラディエント(gradient)、内積(ドット積、スカラー積))

1. $\begin{array}{}\frac{\partial z}{\partial u}\\ =gradf\left(x,y\right)·\left({e}^{u},-{e}^{-u}\right)\\ =\left(\frac{\partial z}{\partial x},\frac{\partial z}{\partial y}\right).\left({e}^{u},-{e}^{-u}\right)\\ =\frac{\partial z}{\partial x}{e}^{u}-\frac{\partial z}{\partial y}{e}^{-u}\end{array}$
$\begin{array}{}\frac{{\partial }^{2}z}{\partial {u}^{2}}\\ =\left(\frac{{\partial }^{2}z}{\partial {x}^{2}},\frac{{\partial }^{2}z}{\partial y\partial x}\right)·\left({e}^{u},-{e}^{-u}\right){e}^{u}+\frac{\partial z}{\partial x}{e}^{u}-\left(\frac{{\partial }^{2}z}{\partial x\partial y},\frac{{\partial }^{2}z}{\partial {y}^{2}}\right)·\left({e}^{u},-{e}^{-u}\right){e}^{-u}-\frac{\partial z}{\partial y}{e}^{-u}\\ =\frac{{\partial }^{2}z}{\partial {x}^{2}}{e}^{2u}-\frac{{\partial }^{2}z}{\partial y\partial x}+\frac{\partial z}{\partial x}{e}^{u}-\frac{{\partial }^{2}z}{\partial x\partial y}+\frac{{\partial }^{2}}{\partial {y}^{2}}{e}^{-2u}+\frac{\partial z}{\partial y}{e}^{-u}\\ =\frac{{\partial }^{2}z}{\partial {x}^{2}}{e}^{2u}-2\frac{{\partial }^{2}z}{\partial x\partial y}+\frac{\partial z}{\partial x}{e}^{u}+\frac{\partial z}{\partial y}{e}^{-u}+\frac{{\partial }^{2}z}{\partial {y}^{2}}{e}^{-2u}\end{array}$
$\frac{\partial z}{\partial v}=\frac{\partial f}{\partial x}{e}^{v}-\frac{\partial f}{\partial y}{e}^{-v}$
$\frac{{\partial }^{2}z}{\partial {v}^{2}}=\frac{{\partial }^{2}z}{\partial {x}^{2}}{e}^{2v}-2\frac{{\partial }^{2}z}{\partial x\partial y}+\frac{\partial z}{\partial x}{e}^{v}+\frac{\partial z}{\partial y}{e}^{-v}+\frac{{\partial }^{2}z}{\partial {y}^{2}}{e}^{-2v}$
$\begin{array}{}\frac{{\partial }^{2}z}{\partial u\partial v}=\left(\frac{\partial f}{\partial x}\left(\frac{\partial f}{\partial x}{e}^{v}-\frac{\partial f}{\partial y}{e}^{-v}\right),\frac{\partial f}{\partial y}\left(\frac{\partial f}{\partial x}{e}^{v}-\frac{\partial f}{\partial y}{e}^{-v}\right)\right)·\left({e}^{u},-{e}^{-u}\right)\\ =\frac{{\partial }^{2}z}{\partial {x}^{2}}{e}^{u+v}-\frac{{\partial }^{2}z}{\partial x\partial y}{e}^{u-v}-\frac{{\partial }^{2}z}{\partial y\partial x}{e}^{v-u}+\frac{{\partial }^{2}z}{\partial {y}^{2}}{e}^{-v-u}\end{array}$
$\begin{array}{}\frac{{\partial }^{2}z}{\partial {u}^{2}}+2\frac{{\partial }^{2}z}{\partial u\partial v}+\frac{{\partial }^{2}z}{\partial {v}^{2}}\\ =\frac{{\partial }^{2}z}{\partial {x}^{2}}\left({e}^{2u}+{e}^{2v}+2{e}^{u+v}\right)+\frac{{\partial }^{2}z}{\partial {y}^{2}}\left({e}^{-2u}+{e}^{-2v}+2{e}^{-\left(u+v\right)}\right)\\ -2\frac{{\partial }^{2}z}{\partial x\mathrm{dy}}\left({e}^{u-v}+{e}^{v-u}+2\right)+\frac{\partial z}{\partial x}\left({e}^{u}+{e}^{v}\right)+\frac{\partial z}{\partial y}\left({e}^{-u}+{e}^{-v}\right)\\ =\frac{{\partial }^{2}z}{\partial {x}^{2}}{\left({e}^{u}+{e}^{v}\right)}^{2}+\frac{{\partial }^{2}z}{\partial {y}^{2}}{\left({e}^{-u}+{e}^{-v}\right)}^{2}-2\left({e}^{n}+{e}^{v}\right)\left({e}^{-u}+{e}^{-v}\right)\frac{{\partial }^{2}z}{\partial x\partial y}+x\frac{\partial z}{\partial x}+y\frac{\partial z}{\partial y}\\ ={x}^{2}\frac{{\partial }^{2}z}{\partial {x}^{2}}+{y}^{2}\frac{{\partial }^{2}z}{\partial {y}^{2}}-2xy\frac{{\partial }^{2}z}{\partial x\partial y}+x\frac{\partial z}{\partial x}+y\frac{\partial z}{\partial y}\end{array}$

コード(Emacs)

Python 3

#!/usr/bin/env python3
from sympy import pprint, symbols, exp, Function, Derivative

u, v = symbols('u, v')
x = exp(u) + exp(v)
y = exp(-u) + exp(-v)
f = Function('f')(x, y)
expr = Derivative(f, u, 2) + 2 * Derivative(Derivative(f, v, 1),
u, 1) + Derivative(f, v, 2)
for t in [expr, expr.doit(), expr.doit().factor()]:
pprint(t)
print()


$./sample3.py ⎛ ⎛ 2 ⎞│ ⎛⎛ 2 ⎞│ ⎜ v ⎜ ∂ ⎛ ⎛ -v -u⎞⎞⎟│ -v ⎜⎜ ∂ ⎟│ 2⋅⎜ℯ ⋅⎜────⎝f⎝ξ₁, ℯ + ℯ ⎠⎠⎟│ - ℯ ⋅⎜⎜───────(f(ξ₁, ξ₂))⎟│ u ⎜ ⎜ 2 ⎟│ u v ⎝⎝∂ξ₂ ∂ξ₁ ⎠│ξ₁=ℯ + ⎝ ⎝∂ξ₁ ⎠│ξ₁=ℯ + ℯ ⎞│ ⎞ ⎛ ⎛⎛ 2 ⎞│ ⎞│ ⎟│ ⎟ u ⎜ v ⎜⎜ ∂ ⎟│ ⎟│ v⎟│ -v -u⎟⋅ℯ - 2⋅⎜ℯ ⋅⎜⎜───────(f(ξ₁, ξ₂))⎟│ -v -u⎟│ u v - ℯ ⎠│ξ₂=ℯ + ℯ ⎟ ⎜ ⎝⎝∂ξ₂ ∂ξ₁ ⎠│ξ₂=ℯ + ℯ ⎠│ξ₁=ℯ + ℯ ⎠ ⎝ ⎛ 2 ⎞│ ⎞ 2 -v ⎜ ∂ ⎛ ⎛ u v ⎞⎞⎟│ ⎟ -u ∂ ⎛ ⎛ u v -v -u⎞⎞ ∂ ℯ ⋅⎜────⎝f⎝ℯ + ℯ , ξ₂⎠⎠⎟│ ⎟⋅ℯ + ───⎝f⎝ℯ + ℯ , ℯ + ℯ ⎠⎠ + ── ⎜ 2 ⎟│ -v -u⎟ 2 ⎝∂ξ₂ ⎠│ξ₂=ℯ + ℯ ⎠ ∂u ∂v 2 ⎛ ⎛ u v -v -u⎞⎞ ─⎝f⎝ℯ + ℯ , ℯ + ℯ ⎠⎠ 2 ⎛ ⎛ 2 ⎞│ ⎛⎛ 2 ⎞│ ⎜ u ⎜ ∂ ⎛ ⎛ -v -u⎞⎞⎟│ -u ⎜⎜ ∂ ⎟│ ⎜ℯ ⋅⎜────⎝f⎝ξ₁, ℯ + ℯ ⎠⎠⎟│ - ℯ ⋅⎜⎜───────(f(ξ₁, ξ₂))⎟│ u v ⎜ ⎜ 2 ⎟│ u v ⎝⎝∂ξ₂ ∂ξ₁ ⎠│ξ₁=ℯ + ℯ ⎝ ⎝∂ξ₁ ⎠│ξ₁=ℯ + ℯ ⎞│ ⎞ ⎛ ⎛⎛ 2 ⎞│ ⎞│ ⎟│ ⎟ u ⎜ u ⎜⎜ ∂ ⎟│ ⎟│ -u ⎟│ -v -u⎟⋅ℯ - ⎜ℯ ⋅⎜⎜───────(f(ξ₁, ξ₂))⎟│ -v -u⎟│ u v - ℯ ⋅ ⎠│ξ₂=ℯ + ℯ ⎟ ⎜ ⎝⎝∂ξ₂ ∂ξ₁ ⎠│ξ₂=ℯ + ℯ ⎠│ξ₁=ℯ + ℯ ⎠ ⎝ ⎛ 2 ⎞│ ⎞ ⎛ ⎛ 2 ⎞│ ⎜ ∂ ⎛ ⎛ u v ⎞⎞⎟│ ⎟ -u ⎜ v ⎜ ∂ ⎛ ⎛ -v -u⎞⎞⎟│ ⎜────⎝f⎝ℯ + ℯ , ξ₂⎠⎠⎟│ ⎟⋅ℯ + 2⋅⎜ℯ ⋅⎜────⎝f⎝ξ₁, ℯ + ℯ ⎠⎠⎟│ ⎜ 2 ⎟│ -v -u⎟ ⎜ ⎜ 2 ⎟│ ⎝∂ξ₂ ⎠│ξ₂=ℯ + ℯ ⎠ ⎝ ⎝∂ξ₁ ⎠│ξ₁=ℯ ⎛⎛ 2 ⎞│ ⎞│ ⎞ ⎛ ⎛ 2 -v ⎜⎜ ∂ ⎟│ ⎟│ ⎟ u ⎜ v ⎜ ∂ ⎛ ⎛ - ℯ ⋅⎜⎜───────(f(ξ₁, ξ₂))⎟│ u v⎟│ -v -u⎟⋅ℯ + ⎜ℯ ⋅⎜────⎝f⎝ u v ⎝⎝∂ξ₂ ∂ξ₁ ⎠│ξ₁=ℯ + ℯ ⎠│ξ₂=ℯ + ℯ ⎟ ⎜ ⎜ 2 + ℯ ⎠ ⎝ ⎝∂ξ₁ ⎞│ ⎛⎛ 2 ⎞│ ⎞│ -v -u⎞⎞⎟│ -v ⎜⎜ ∂ ⎟│ ⎟│ ξ₁, ℯ + ℯ ⎠⎠⎟│ - ℯ ⋅⎜⎜───────(f(ξ₁, ξ₂))⎟│ u v⎟│ -v ⎟│ u v ⎝⎝∂ξ₂ ∂ξ₁ ⎠│ξ₁=ℯ + ℯ ⎠│ξ₂=ℯ + ℯ ⎠│ξ₁=ℯ + ℯ ⎞ ⎛ ⎛⎛ 2 ⎞│ ⎞│ ⎛ 2 ⎟ v ⎜ v ⎜⎜ ∂ ⎟│ ⎟│ -v ⎜ ∂ ⎛ ⎛ u -u⎟⋅ℯ - ⎜ℯ ⋅⎜⎜───────(f(ξ₁, ξ₂))⎟│ -v -u⎟│ u v - ℯ ⋅⎜────⎝f⎝ℯ + ⎟ ⎜ ⎝⎝∂ξ₂ ∂ξ₁ ⎠│ξ₂=ℯ + ℯ ⎠│ξ₁=ℯ + ℯ ⎜ 2 ⎠ ⎝ ⎝∂ξ₂ ⎞│ ⎞ ⎛ ⎛⎛ 2 ⎞│ ⎞│ v ⎞⎞⎟│ ⎟ -v ⎜ v ⎜⎜ ∂ ⎟│ ⎟│ ℯ , ξ₂⎠⎠⎟│ ⎟⋅ℯ - 2⋅⎜ℯ ⋅⎜⎜───────(f(ξ₁, ξ₂))⎟│ -v -u⎟│ u ⎟│ -v -u⎟ ⎜ ⎝⎝∂ξ₂ ∂ξ₁ ⎠│ξ₂=ℯ + ℯ ⎠│ξ₁=ℯ ⎠│ξ₂=ℯ + ℯ ⎠ ⎝ ⎛ 2 ⎞│ ⎞ -v ⎜ ∂ ⎛ ⎛ u v ⎞⎞⎟│ ⎟ -u u ⎛ ∂ ⎛ ⎛ -v -u v - ℯ ⋅⎜────⎝f⎝ℯ + ℯ , ξ₂⎠⎠⎟│ ⎟⋅ℯ + ℯ ⋅⎜───⎝f⎝ξ₁, ℯ + ℯ + ℯ ⎜ 2 ⎟│ -v -u⎟ ⎝∂ξ₁ ⎝∂ξ₂ ⎠│ξ₂=ℯ + ℯ ⎠ ⎞⎞⎞│ v ⎛ ∂ ⎛ ⎛ -v -u⎞⎞⎞│ -v ⎛ ∂ ⎛ ⎛ u v ⎠⎠⎟│ u v + ℯ ⋅⎜───⎝f⎝ξ₁, ℯ + ℯ ⎠⎠⎟│ u v + ℯ ⋅⎜───⎝f⎝ℯ + ℯ , ξ ⎠│ξ₁=ℯ + ℯ ⎝∂ξ₁ ⎠│ξ₁=ℯ + ℯ ⎝∂ξ₂ ⎞⎞⎞│ -u ⎛ ∂ ⎛ ⎛ u v ⎞⎞⎞│ ₂⎠⎠⎟│ -v -u + ℯ ⋅⎜───⎝f⎝ℯ + ℯ , ξ₂⎠⎠⎟│ -v -u ⎠│ξ₂=ℯ + ℯ ⎝∂ξ₂ ⎠│ξ₂=ℯ + ℯ ⎛ ⎛ 2 ⎞│ ⎛ 2 ⎛ u v⎞ ⎜ 3⋅u 2⋅v ⎜ ∂ ⎛ ⎛ -v -u⎞⎞⎟│ 2⋅u 3⋅v ⎜ ∂ ⎛ ⎛ ⎝ℯ + ℯ ⎠⋅⎜ℯ ⋅ℯ ⋅⎜────⎝f⎝ξ₁, ℯ + ℯ ⎠⎠⎟│ + ℯ ⋅ℯ ⋅⎜────⎝f⎝ξ ⎜ ⎜ 2 ⎟│ u v ⎜ 2 ⎝ ⎝∂ξ₁ ⎠│ξ₁=ℯ + ℯ ⎝∂ξ₁ ⎞│ -v -u⎞⎞⎟│ 2⋅u 2⋅v ⎛ ∂ ⎛ ⎛ -v -u⎞⎞⎞│ ₁, ℯ + ℯ ⎠⎠⎟│ + ℯ ⋅ℯ ⋅⎜───⎝f⎝ξ₁, ℯ + ℯ ⎠⎠⎟│ u v - 2⋅ ⎟│ u v ⎝∂ξ₁ ⎠│ξ₁=ℯ + ℯ ⎠│ξ₁=ℯ + ℯ ⎛⎛ 2 ⎞│ ⎞│ ⎛⎛ 2 2⋅u v ⎜⎜ ∂ ⎟│ ⎟│ u 2⋅v ⎜⎜ ∂ ℯ ⋅ℯ ⋅⎜⎜───────(f(ξ₁, ξ₂))⎟│ -v -u⎟│ u v - 2⋅ℯ ⋅ℯ ⋅⎜⎜───────(f ⎝⎝∂ξ₂ ∂ξ₁ ⎠│ξ₂=ℯ + ℯ ⎠│ξ₁=ℯ + ℯ ⎝⎝∂ξ₂ ∂ξ₁ ⎞│ ⎞│ ⎟│ ⎟│ u v ⎛ ∂ ⎛ ⎛ u v ⎞⎞⎞│ (ξ₁, ξ₂))⎟│ -v -u⎟│ u v + ℯ ⋅ℯ ⋅⎜───⎝f⎝ℯ + ℯ , ξ₂⎠⎠⎟│ -v -u ⎠│ξ₂=ℯ + ℯ ⎠│ξ₁=ℯ + ℯ ⎝∂ξ₂ ⎠│ξ₂=ℯ + ℯ ⎛ 2 ⎞│ ⎛ 2 ⎞│ u ⎜ ∂ ⎛ ⎛ u v ⎞⎞⎟│ v ⎜ ∂ ⎛ ⎛ u v ⎞⎞⎟│ + ℯ ⋅⎜────⎝f⎝ℯ + ℯ , ξ₂⎠⎠⎟│ + ℯ ⋅⎜────⎝f⎝ℯ + ℯ , ξ₂⎠⎠⎟│ ⎜ 2 ⎟│ -v -u ⎜ 2 ⎟│ -v ⎝∂ξ₂ ⎠│ξ₂=ℯ + ℯ ⎝∂ξ₂ ⎠│ξ₂=ℯ + ⎞ ⎟ -2⋅u -2⋅v ⎟⋅ℯ ⋅ℯ -u⎟ ℯ ⎠$