mirror of
https://github.com/MartinThoma/LaTeX-examples.git
synced 2025-04-19 11:38:05 +02:00
Added visualization of the EEA
This commit is contained in:
parent
79b2f53b54
commit
42bc49a23d
5 changed files with 12263 additions and 0 deletions
35
tikz/extended-euclidean-algorithm-runtime/Makefile
Normal file
35
tikz/extended-euclidean-algorithm-runtime/Makefile
Normal file
|
@ -0,0 +1,35 @@
|
|||
SOURCE = extended-euclidean-algorithm-runtime
|
||||
DELAY = 80
|
||||
DENSITY = 300
|
||||
WIDTH = 512
|
||||
|
||||
make:
|
||||
pdflatex $(SOURCE).tex -output-format=pdf
|
||||
make clean
|
||||
|
||||
clean:
|
||||
rm -rf $(TARGET) *.class *.html *.log *.aux *.data *.gnuplot
|
||||
|
||||
gif:
|
||||
pdfcrop $(SOURCE).pdf
|
||||
convert -verbose -delay $(DELAY) -loop 0 -density $(DENSITY) $(SOURCE)-crop.pdf $(SOURCE).gif
|
||||
make clean
|
||||
|
||||
png:
|
||||
make
|
||||
make svg
|
||||
inkscape $(SOURCE).svg -w $(WIDTH) --export-png=$(SOURCE).png
|
||||
|
||||
transparentGif:
|
||||
convert $(SOURCE).pdf -transparent white result.gif
|
||||
make clean
|
||||
|
||||
svg:
|
||||
make
|
||||
#inkscape $(SOURCE).pdf --export-plain-svg=$(SOURCE).svg
|
||||
pdf2svg $(SOURCE).pdf $(SOURCE).svg
|
||||
# Necessary, as pdf2svg does not always create valid svgs:
|
||||
inkscape $(SOURCE).svg --export-plain-svg=$(SOURCE).svg
|
||||
rsvg-convert -a -w $(WIDTH) -f svg $(SOURCE).svg -o $(SOURCE)2.svg
|
||||
inkscape $(SOURCE)2.svg --export-plain-svg=$(SOURCE).svg
|
||||
rm $(SOURCE)2.svg
|
8
tikz/extended-euclidean-algorithm-runtime/README.md
Normal file
8
tikz/extended-euclidean-algorithm-runtime/README.md
Normal file
|
@ -0,0 +1,8 @@
|
|||
Compiled example
|
||||
----------------
|
||||

|
||||
|
||||
|
||||
TeX main memory
|
||||
---------------
|
||||
You might need to give tex more main memory: http://tex.stackexchange.com/questions/75399/increasing-texs-main-memory
|
12101
tikz/extended-euclidean-algorithm-runtime/data.csv
Normal file
12101
tikz/extended-euclidean-algorithm-runtime/data.csv
Normal file
File diff suppressed because it is too large
Load diff
42
tikz/extended-euclidean-algorithm-runtime/eea.py
Executable file
42
tikz/extended-euclidean-algorithm-runtime/eea.py
Executable file
|
@ -0,0 +1,42 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import csv
|
||||
|
||||
|
||||
def eea(a, b):
|
||||
"""
|
||||
Calculates u*a + v*b = ggT
|
||||
returns (ggT, u, v, steps)
|
||||
"""
|
||||
u, v, s, t, steps = 1, 0, 0, 1, 0
|
||||
while b > 0:
|
||||
q = a//b
|
||||
a, b = b, a-q*b
|
||||
u, s = s, u-q*s
|
||||
v, t = t, v-q*t
|
||||
steps += 1
|
||||
return a, u, v, steps
|
||||
|
||||
|
||||
def create_csv(n, filename):
|
||||
max_steps = 0
|
||||
with open(filename, 'wb') as csvfile:
|
||||
csvwriter = csv.writer(csvfile, delimiter=',',
|
||||
quotechar='"', quoting=csv.QUOTE_MINIMAL)
|
||||
csvwriter.writerow(["x", "y", "steps"])
|
||||
for x in range(n):
|
||||
for y in range(n):
|
||||
steps = eea(x, y)[-1]
|
||||
max_steps = max(steps, max_steps)
|
||||
csvwriter.writerow([x, y, steps])
|
||||
print("Maximum step number: %i" % max_steps)
|
||||
|
||||
if __name__ == "__main__":
|
||||
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
|
||||
parser = ArgumentParser(description=__doc__,
|
||||
formatter_class=ArgumentDefaultsHelpFormatter)
|
||||
parser.add_argument("-n",
|
||||
dest="n", default=10, type=int,
|
||||
help="how many lines get printed")
|
||||
args = parser.parse_args()
|
||||
create_csv(args.n, "data.csv")
|
|
@ -0,0 +1,77 @@
|
|||
\documentclass[varwidth=true, border=5pt]{article}
|
||||
\usepackage[active,tightpage]{preview}
|
||||
\usepackage[latin1]{inputenc}
|
||||
\usepackage{amsmath}
|
||||
\usepackage{pgfplots}
|
||||
\pgfplotsset{compat=1.10}
|
||||
\usepackage{tikz}
|
||||
\usetikzlibrary{arrows, positioning}
|
||||
\usepackage{helvet}
|
||||
\usepackage[eulergreek]{sansmath}
|
||||
|
||||
\begin{document}
|
||||
\begin{preview}
|
||||
\pgfplotsset{
|
||||
colormap={whitered}{
|
||||
color(0cm)=(white);
|
||||
color(1cm)=(orange!75!red)
|
||||
}
|
||||
}
|
||||
\begin{tikzpicture}
|
||||
\begin{axis}[
|
||||
colormap name=whitered,
|
||||
clip mode=individual,
|
||||
width=10.0cm,
|
||||
height=10.0cm,
|
||||
% Grid
|
||||
grid = major,
|
||||
% size
|
||||
%xmin= 40, % start the diagram at this x-coordinate
|
||||
%xmax= 90, % end the diagram at this x-coordinate
|
||||
%ymin= 0, % start the diagram at this y-coordinate
|
||||
%ymax= 60, % end the diagram at this y-coordinate
|
||||
% Legende
|
||||
legend style={
|
||||
font=\large\sansmath\sffamily,
|
||||
at={(0.5,-0.18)},
|
||||
anchor=north,
|
||||
legend cell align=left,
|
||||
legend columns=-1,
|
||||
column sep=0.5cm
|
||||
},
|
||||
% Ticks
|
||||
tick align=inside,
|
||||
every axis/.append style={font=\large\sansmath\sffamily},
|
||||
minor tick style={thick},
|
||||
scaled y ticks = false,
|
||||
% Axis
|
||||
axis line style = {very thick,shorten <=-0.5\pgflinewidth},
|
||||
axis lines = middle,
|
||||
axis line style = very thick,
|
||||
xlabel=$m$,
|
||||
x label style={at={(axis description cs:0.5,-0.05)},
|
||||
anchor=north,
|
||||
font=\boldmath\sansmath\sffamily\Large},
|
||||
ylabel=$n$,
|
||||
y label style={at={(axis description cs:-0.1,0.5)},
|
||||
anchor=south,
|
||||
rotate=90,
|
||||
font=\boldmath\sansmath\sffamily\Large},
|
||||
colorbar,
|
||||
colorbar style={
|
||||
at={(-0.2,0)},
|
||||
anchor=south west,
|
||||
height=0.25*\pgfkeysvalueof{/pgfplots/parent axis height},
|
||||
title={Schritte} % ADJUST THIS TO YOUR LANGUAGE
|
||||
}
|
||||
]
|
||||
\addplot[
|
||||
scatter,
|
||||
only marks,
|
||||
mark=square*
|
||||
]
|
||||
table[col sep=comma,point meta=\thisrow{steps}] {data.csv};
|
||||
\end{axis}
|
||||
\end{tikzpicture}
|
||||
\end{preview}
|
||||
\end{document}
|
Loading…
Add table
Add a link
Reference in a new issue