学習環境
- Surface 3 (4G LTE)、Surface 3 タイプ カバー、Surface ペン(端末)
- Windows 10 Pro (OS)
- 数式入力ソフト(TeX, MathML): MathType
- MathML対応ブラウザ: Firefox、Safari
- MathML非対応ブラウザ(Internet Explorer, Google Chrome...)用JavaScript Library: MathJax
- Pythonからはじめる数学入門(参考書籍)
ラング線形代数学(上)(S.ラング (著)、芹沢 正三 (翻訳)、ちくま学芸文庫)の2章(ベクトル空間)、3(基底)、練習問題2、3.を取り組んでみる。
コード(Emacs)
Python 3
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from sympy import Symbol, solve
x = Symbol('x')
y = Symbol('y')
z = Symbol('z')
exprs = [((1, 0), (1, 1), (0, 1)),
((2, 1), (1, -1), (1, 1)),
((1, 1), (2, 1), (-1, 0)),
((4, 3), (2, 1), (-1, 0))]
for i, ((x1, x2), (a1, a2), (b1, b2)) in enumerate(exprs):
print('({0})'.format(chr(ord('a') + i)))
expr1 = x * a1 + y * b1 - x1
expr2 = x * a2 + y * b2 - x2
print(solve((expr1, expr2), dict=True))
exprs = [((1, 0, 0), (1, 1, 1), (-1, 1, 0), (1, 0, -1)),
((1, 1, 1), (0, 1, -1), (1, 1, 0), (1, 0, 2)),
((0, 0, 1), (1, 1, 1), (-1, 1, 0), (1, 0, -1))]
for i, ((x1, x2, x3),
(a1, a2, a3), (b1, b2, b3), (c1, c2, c3)) in enumerate(exprs):
print('({0})'.format(chr(ord('a') + i)))
expr1 = x * a1 + y * b1 + z * c1 - x1
expr2 = x * a2 + y * b2 + z * c2 - x2
expr3 = x * a3 + y * b3 + z * c3 - x3
print(solve((expr1, expr2, expr3), dict=True))
入出力結果(Terminal, IPython)
$ ./sample2.py
(a)
[{x: 1, y: -1}]
(b)
[{x: 1/2, y: 3/2}]
(c)
[{x: 1, y: 1}]
(d)
[{x: 3, y: 2}]
(a)
[{x: 1/3, y: -1/3, z: 1/3}]
(b)
[{x: 1, y: 0, z: 1}]
(c)
[{x: 1/3, y: -1/3, z: -2/3}]
$
0 コメント:
コメントを投稿