瀏覽代碼

added plot of cubic function

Martin Thoma 13 年之前
父節點
當前提交
2d7f2ff7c5
共有 2 個文件被更改,包括 84 次插入0 次删除
  1. 31 0
      tikz/cubic-function/Makefile
  2. 53 0
      tikz/cubic-function/cubic-function.tex

+ 31 - 0
tikz/cubic-function/Makefile

@@ -0,0 +1,31 @@
+SOURCE = cubic-function
+DELAY = 80
+DENSITY = 300
+WIDTH = 500
+
+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:
+	#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

+ 53 - 0
tikz/cubic-function/cubic-function.tex

@@ -0,0 +1,53 @@
+\documentclass{article}
+\usepackage[pdftex,active,tightpage]{preview}
+\setlength\PreviewBorder{2mm}
+  
+\usepackage{pgfplots}
+\usepackage{tikz}
+\usetikzlibrary{arrows, positioning, calc, intersections}
+ 
+\begin{document}
+
+% Define this as a command to ensure that it is same in both cases
+\newcommand*{\ShowIntersection}[2]{
+\fill 
+    [name intersections={of=#1 and #2, name=i, total=\t}] 
+    [red, opacity=1, every node/.style={above left, black, opacity=1}] 
+    \foreach \s in {1,...,\t}{(i-\s) circle (2pt)
+        node [above left] {\s}};
+}
+
+\begin{preview}
+\begin{tikzpicture}
+    \begin{axis}[
+    axis x line=middle,
+    axis y line=middle,
+        width=15cm, height=15cm,     % size of the image
+        grid = major,
+        grid style={dashed, gray!30},
+        %xmode=log,log basis x=10,
+        %ymode=log,log basis y=10,
+        xmin=-2,     % start the diagram at this x-coordinate
+        xmax= 4,    % end   the diagram at this x-coordinate
+        ymin=-7,     % start the diagram at this y-coordinate
+        ymax= 7,   % end   the diagram at this y-coordinate
+        %/pgfplots/xtick={0,1,...,60}, % make steps of length 5
+        %extra x ticks={23},
+        %extra y ticks={0.507297},
+        axis background/.style={fill=white},
+        ylabel=y,
+        xlabel=x,
+        %xticklabels={,,},
+        %yticklabels={,,},
+        tick align=outside,
+        tension=0.08]
+      % plot the stirling-formulae
+      \addplot[name path global=a, domain=-2:4, red, thick,samples=500] 
+        {-x*x*x + 4*x*x-x-4}; 
+      \addplot[name path global=b, domain=0.25:4, blue, thick, dashed] {x-1.2}; 
+      \addplot[name path global=c, domain=0.25:4, blue, thick, dashed] {x+0.42}; 
+      \ShowIntersection{a}{b};
+    \end{axis} 
+\end{tikzpicture}
+\end{preview}
+\end{document}