summaryrefslogtreecommitdiffstats
path: root/one.py
diff options
context:
space:
mode:
authorsyn <isaqtm@gmail.com>2020-02-16 11:56:52 +0300
committersyn <isaqtm@gmail.com>2020-02-16 11:56:52 +0300
commitfd78d0fd00e6b98ae8b9894db8be028575e205ac (patch)
treeee9dd35e871d222aa60a1958e9b6f28eaa6ecc54 /one.py
downloadalg3-fd78d0fd00e6b98ae8b9894db8be028575e205ac.tar.gz
Init commit
Diffstat (limited to 'one.py')
-rw-r--r--one.py114
1 files changed, 114 insertions, 0 deletions
diff --git a/one.py b/one.py
new file mode 100644
index 0000000..854164e
--- /dev/null
+++ b/one.py
@@ -0,0 +1,114 @@
+from libsolve import *
+from fractions import Fraction
+import numpy as np
+
+ONE_SIMEQ = '\\overset{{\\texttt{{one.py}}}}\\simeq'
+
+# generate figure as plain file, so we can \input it
+def gen_figure(figname, text):
+ with open(f'figures/fig_one_{figname}.tex', 'w') as fd:
+ fd.write('$$' + text + '$$')
+
+m = Matrix([
+ [-1, 4, 1, -2, 1, 3],
+ [-1, 4, 1, -2, 1, 3],
+ [1, -4, 3, -2, 7, 5]
+])
+
+
+vectors = [
+ [3, 1, -7, -3, 3, -1],
+ [2, 2, 5, 3, 1, -2],
+]
+for i, v in enumerate(vectors):
+ v_t = Matrix([[i] for i in [3, 1, -7, -3, 3, -1]])
+ gen_figure(f'proof_v{i}',
+ f'''
+ {m.to_tex()}
+ \\times
+ {v_t.to_tex()}
+ =
+ {(m @ v_t).to_tex()}
+ ''')
+
+init = m.to_tex()
+m.make_S(0, 1, -1)
+m.make_S(1, 2, 1)
+m.make_D(1, Fraction(1, 4))
+m.make_S(2, 1, -3)
+
+init_triang = m.to_tex()
+
+gen_figure('init_to_triang',
+f'''
+ {init}
+ {ONE_SIMEQ}
+ {init_triang}
+''')
+
+
+
+
+
+# steps are the same every time, cause we change only last col
+def convert_steps(mat, mat_no):
+ before = mat.to_tex()
+ mat.make_S(0, 1, -4)
+ mat.make_S(2, 0, 1)
+ mat.make_S(3, 0, 1)
+ mat.make_D(0, -1)
+ mat.make_S(0, 4, -1)
+ mat.make_S(2, 4, 3)
+ mat.make_S(3, 4, 1)
+
+ mat.make_S(0, 5, 1)
+ mat.make_S(2, 5, 1)
+ mat.make_S(3, 5, -1)
+ after = mat.to_tex()
+
+ gen_figure(f'convert_v{mat_no}',
+ f'''
+ {before}
+ {ONE_SIMEQ}
+ {after}
+ ''')
+
+convert_steps(Matrix([
+ [4,-1,-1,1,3],
+ [1,0,0,0,1],
+ [0,1,-2,-2,-7],
+ [0,1,0,0,-3],
+ [0,0,1,0,3],
+ [0,0,0,1,-1]
+]), 1)
+
+
+convert_steps(Matrix([
+ [4,-1,-1,1,2],
+ [1,0,0,0,2],
+ [0,1,-2,-2,5],
+ [0,1,0,0,3],
+ [0,0,1,0,1],
+ [0,0,0,1,-2]
+]), 2)
+
+
+
+
+
+
+m = Matrix([
+ [1, -3, 3, 1],
+ [2, 3, 1, -2]
+])
+
+before = m.to_tex()
+m.make_S(1, 0, -2)
+after = m.to_tex()
+
+gen_figure('solve_last',
+f'''
+ {before}
+ {ONE_SIMEQ}
+ {after}
+''')