2020年1月30日木曜日

学習環境

ラング線形代数学(上) (ちくま学現文庫)(S.ラング (著)、芹沢 正三 (翻訳)、筑摩書房)の3章(行列)、1(1次方程式)、練習問題3の解答を求めてみる。



    1. -7y=3y=372x=5-3·37x=125-97=12·267=137

    2. 3x+y=1x-y=-24x=-1x=-14y=-14+2=74z=14-7+2=1-28+84=-194

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import symbols, solve, Rational

print('3.')

x, y, z = symbols('x, y, z', real=True)


class MyTestCase(TestCase):
    def test_a(self):
        self.assertEqual(solve((2 * x + 3 * y - 5, 4 * x - y - 7)),
                         {x: Rational(13, 7), y: Rational(3, 7)})

    def test_b(self):
        self.assertEqual(solve((2 * x + 3 * y + z,
                                x - 2 * y - z - 1,
                                x + 4 * y + z - 2)),
                         {x: -Rational(1, 4), y: Rational(7, 4), z: -Rational(19, 4)})


if __name__ == '__main__':
    main()

入出力結果(Zsh、PowerShell、Terminal、Jupyter(IPython))

% ./sample3.py -v
3.
test_a (__main__.MyTestCase) ... ok
test_b (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 2 tests in 0.066s

OK
%

0 コメント:

コメントを投稿