#!/usr/bin/env python3from sympy import pprint, symbols, Matrix, solve
x, y, z, w = symbols('x, y, z, w')
exprs = [
(
3 * x + y + z + 5,
4 * x + 3 * y - z + 2,
5 * x + 4 * y + z - 6
),
(
x + 2 * y - z - w - 3,
x - y + z + w - 3,
x - y - z - 4,
x + w - 4
)
]
for i, expr inenumerate(exprs):
print(f'({chr(ord("a") + i)})')
for t in [expr, solve(expr)]:
pprint(t)
print()
print()
入出力結果(Terminal, Jupyter(IPython))
$ ./sample6.py
(a)
(3⋅x + y + z + 5, 4⋅x + 3⋅y - z + 2, 5⋅x + 4⋅y + z - 6)
{x: -5, y: 7, z: 3}
(b)
(-w + x + 2⋅y - z - 3, w + x - y + z - 3, x - y - z - 4, w + x - 4)
{w: 1, x: 3, y: 0, z: -1}
$
0 コメント:
コメントを投稿