## 2020年4月4日土曜日

### 数学 - Python - 解析学 - 多変数の関数 - 多変数の関数 - 偏微分 - 指数関数、対数関数、偏微分

1. $\begin{array}{l}f\left(x,y\right)\\ ={x}^{y}\\ ={e}^{y\mathrm{log}x}\\ \frac{\partial f}{\partial x}=y{x}^{y-1}\\ \frac{\partial f}{\partial y}\\ ={e}^{y\mathrm{log}x}\mathrm{log}x\\ ={x}^{y}\mathrm{log}x\end{array}$

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import symbols, Matrix, exp, log, Derivative, plot
from sympy.plotting import plot3d, plot_parametric
import random

print('14.')

x, y = symbols('x, y')
f = x ** y
dfdx = y * x ** (y - 1)
dfdy = x ** y * log(x)

def test_dx(self):
self.assertEqual(Derivative(f, x, 1).doit().simplify(),
dfdx)

def test_dy(self):
self.assertEqual(Derivative(f, y, 1).doit(),
dfdy)

p = plot3d(f, (x, 5, 10), (y, 5, 10), show=False)
p.save('sample14.png')
p.xlabel = x
p.ylabel = y

p.show()

if __name__ == "__main__":
main()


% ./sample14.py -v
14.
test_dx (__main__.TestGrad) ... ok
test_dy (__main__.TestGrad) ... ok

----------------------------------------------------------------------
Ran 2 tests in 0.241s

OK
%