File binomischeformeln.py added (mode: 100644) (index 0000000..a147186) |
|
1 |
|
import numpy as np |
|
2 |
|
import sympy as s |
|
3 |
|
from sympy import pprint, Symbol, sin, exp, sqrt, series, latex, symbols, simplify, expand |
|
4 |
|
from sympy import init_printing |
|
5 |
|
|
|
6 |
|
cols = 2 |
|
7 |
|
rows = 5 |
|
8 |
|
|
|
9 |
|
def pl(expression): |
|
10 |
|
print(latex(expression)) |
|
11 |
|
|
|
12 |
|
|
|
13 |
|
def pls(expression): |
|
14 |
|
print(latex(simplify(expression))) |
|
15 |
|
|
|
16 |
|
|
|
17 |
|
def ple(expression): |
|
18 |
|
print(latex(expand(expression))) |
|
19 |
|
|
|
20 |
|
|
|
21 |
|
def l(expression): |
|
22 |
|
return latex(expression) |
|
23 |
|
|
|
24 |
|
|
|
25 |
|
def ls(expression): |
|
26 |
|
return latex(simplify(expression)) |
|
27 |
|
|
|
28 |
|
|
|
29 |
|
def le(expression): |
|
30 |
|
return latex(expand(expression)) |
|
31 |
|
|
|
32 |
|
def a2list(list): |
|
33 |
|
temp = [] |
|
34 |
|
for i in range(len(list)): |
|
35 |
|
temp.append(list[i]) |
|
36 |
|
return temp |
|
37 |
|
|
|
38 |
|
def a2l(list): |
|
39 |
|
temp = [] |
|
40 |
|
for i in range(len(list)): |
|
41 |
|
temp.append(l(list[i])) |
|
42 |
|
return temp |
|
43 |
|
def a2le(list): |
|
44 |
|
temp = [] |
|
45 |
|
for i in range(len(list)): |
|
46 |
|
temp.append(le(list[i])) |
|
47 |
|
return temp |
|
48 |
|
|
|
49 |
|
def binomischeform1(test1): |
|
50 |
|
out_ang = "\\begin{equation*} \n" |
|
51 |
|
for i in range(len(a2l(test1))): |
|
52 |
|
if i%rows is 0: |
|
53 |
|
out_ang += "\\begin{aligned}[c]\n"+a2l(test1)[i]+"\\\\" |
|
54 |
|
if i%rows is not 0 and i%rows is not rows-1: |
|
55 |
|
out_ang += a2l(test1)[i] + " \\\\ " |
|
56 |
|
if i%rows is rows-1: |
|
57 |
|
out_ang += a2l(test1)[i]+"\n\\end{aligned} \n\\qquad\\qquad \n" |
|
58 |
|
#out_ang = " \\\\ ".join(a2l(test1))+"" |
|
59 |
|
out_ang += "\\end{equation*}" |
|
60 |
|
out_los = "\\section{Lösung:}\n\\begin{equation*} \n \hspace{-" + str(cols * 20) + "px}" |
|
61 |
|
for i in range(len(a2l(test1))): |
|
62 |
|
if i % rows is 0: |
|
63 |
|
out_los += "\\begin{aligned}[c]\n" + a2le(test1)[i] + "\\\\" |
|
64 |
|
if i % rows is not 0 and i % rows is not rows - 1: |
|
65 |
|
out_los += a2le(test1)[i] + " \\\\ " |
|
66 |
|
if i % rows is rows - 1: |
|
67 |
|
out_los += a2le(test1)[i] + "\n\\end{aligned} \n\\qquad \n" |
|
68 |
|
# out_ang = " \\\\ ".join(a2l(test1))+"" |
|
69 |
|
out_los += "\\end{equation*}" |
|
70 |
|
return out_ang, out_los |
|
71 |
|
x, y, z, a, b, c = symbols('x y z a b c') |
|
72 |
|
|
|
73 |
|
test1 = (np.random.randint(1, 11, cols * rows)*a+np.random.randint(1, 11, cols*rows)*b)**2 |
|
74 |
|
|
|
75 |
|
|
|
76 |
|
#print(out_ang) |
|
77 |
|
|
|
78 |
|
#print("{0}\n{1}".format(binomischeform1(test1))) |
|
79 |
|
#print(len(binomischeform1(test1))) |
|
80 |
|
|
|
81 |
|
b = binomischeform1(test1) |
|
82 |
|
|
|
83 |
|
# print(b[0]) |
|
84 |
|
# print(b[1]) |
|
85 |
|
|
|
86 |
|
f = open("latexout2.tex", "w") |
|
87 |
|
f.write("{}\n{}".format(b[0],b[1])) |
|
88 |
|
|
|
89 |
|
#print("{}\n{}".format(b[0],b[1])) |