## 2020年4月13日月曜日

### 数学 - Python - 解析学 - 多変数の関数 - 多変数の関数 - 誤差項の評価、絶対値、不等式、ベクトル、ノルム

1. $\begin{array}{l}\left|{h}^{2}+3hk\right|\\ \le \left|{h}^{2}\right|+\left|3hk\right|\\ \le {\left|h\right|}^{2}+3|h\parallel \left|k\right|\\ \le {∥H∥}^{2}+3∥H∥∥H∥\\ \le {∥H∥}^{2}+3{∥H∥}^{2}\\ \le 4{∥H∥}^{2}\end{array}$

2. $\begin{array}{l}\left|{h}^{3}+{h}^{2}k+{k}^{3}\right|\\ \le {\left|h\right|}^{3}+{\left|h\right|}^{2}\left|k\right|+{\left|k\right|}^{3}\\ \le {∥H∥}^{3}+{∥H∥}^{3}+{∥H∥}^{3}\\ \le 3{∥H∥}^{3}\end{array}$

3. $\begin{array}{l}\left|3h{k}^{2}+2{h}^{3}\right|\\ \le 3{∥H∥}^{3}+2{∥H∥}^{3}\\ \le 5{∥H∥}^{3}\end{array}$

4. $\begin{array}{l}∥{\left(h+k\right)}^{4}∥\\ =\left|{h}^{4}+4{h}^{3}k+6{h}^{2}{k}^{2}+4h{k}^{3}+{k}^{4}\right|\\ \le 16{∥H∥}^{4}\end{array}$

5. $\begin{array}{l}\left|{\left(h+k\right)}^{3}\right|\\ =\left|{h}^{3}+3{h}^{2}k+3h{k}^{2}+{k}^{3}\right|\\ \le 8{∥H∥}^{2}\end{array}$

コード

#!/usr/bin/env python3
import random
from unittest import TestCase, main
from sympy import symbols, Matrix

print('6.')

class TestInequalities(TestCase):
def test(self):
h, k = symbols('h, k', real=True)
for _ in range(10):
h, k = [random.randrange(-100, 101) for _ in range(2)]
H = Matrix([h, k])
for a, (b, c) in [(h ** 2 + 3 * h * k, (4, 3)),
(h ** 3 + h ** 2 *
k + k ** 3, (3, 3)),
(3 * h * k ** 2 + 2 * h ** 3, (5, 3)),
((h + k) ** 4, (16, 4)),
((h + k) ** 3, (3, 3))]:
self.assertLessEqual(abs(a), b * H.norm() ** c)

if __name__ == "__main__":
main()


% ./sample6.py -v
6.
test (__main__.TestInequalities) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.097s

OK
%