Some examples
A lot of examples about Tikz [A PGF and TikZ examples gallery] can be found on the beautiful site of
Kjell Magne Fauske :
A PGF and TikZ examples gallery
Product of matrices
Product of matrices :
[PDF]
[TEX]
\documentclass[]{article}
\usepackage[utf8]{inputenc}
\usepackage[upright]{fourier}
\usepackage{tikz}
\usetikzlibrary{matrix,arrows,decorations.pathmorphing}
\usepackage{fullpage}
\begin{document}
To multiply two matrices, the first matrix must have the same number of rows (p) as the second matrix has columns (q). In other words, p of the first matrix must equal q of the second matrix. In general terms, a matrix C which is a product of two matrices, A and B, will have elements given by the following
\[c_{ij}=\sum_{k=1}^p a_{ik}b_{kj}\]
where $i$ = ith row and $j$ = jth column
\begin{tikzpicture}[>=latex]
\newcommand{\myunit}{1.2 cm}
\tikzset{node style sp/.style={draw,circle,minimum size=\myunit}}
\tikzset{node style ge/.style={circle,minimum size=\myunit}}
\tikzset{arrow style mul/.style={draw,sloped,midway,fill=white}}
\tikzset{arrow style plus/.style={midway,sloped,fill=white}}
\matrix (A) [matrix of math nodes, nodes = {node style ge}, left delimiter = (, right delimiter = )] at (0,0)
{ a_{11} &\ldots & a_{1k} & \ldots & a_{1p} \\
\vdots & \ddots & \vdots & \vdots & \vdots \\
\node[node style sp] {a_{i1}};& \ldots & \node[node style sp] {a_{ik}}; & \ldots & \node[node style sp] {a_{ip}}; \\
\vdots & \vdots& \vdots & \ddots & \vdots \\
a_{n1}& \ldots & a_{nk} & \ldots & a_{np} \\
};
\node [draw,below] at (A.south) { $A$ : \textcolor{red}{$n$ rows} $p$ columns};
\matrix (B) [matrix of math nodes, nodes = {node style ge}, left delimiter = (, right delimiter =)] at (7*\myunit,7*\myunit)
{ b_{11} & \ldots& \node[node style sp] {b_{1j}}; & \ldots & b_{1q} \\
\vdots& \ddots & \vdots & \vdots & \vdots \\
b_{k1} & \ldots& \node[node style sp] {b_{kj}}; & \ldots & b_{kq} \\
\vdots& \vdots & \vdots & \ddots & \vdots \\
b_{p1} & \ldots& \node[node style sp] {b_{pj}}; & \ldots & b_{pq} \\
};
\node [draw,above] at (B.north) { $B$ : $p$ rows \textcolor{red}{$q$ columns}};
\matrix (C) [matrix of math nodes, nodes = {node style ge}, left delimiter = (, right delimiter = )] at (7*\myunit,0)
{ c_{11} & \ldots& c_{1j} & \ldots & c_{1q} \\
\vdots& \ddots & \vdots & \vdots & \vdots \\
c_{i1}& \ldots & \node[node style sp,red] {c_{ij}}; & \ldots & c_{iq} \\
\vdots& \vdots & \vdots & \ddots & \vdots \\
c_{n1}& \ldots & c_{nk} & \ldots & c_{nq} \\
};
\node [draw,below] at (C.south) {$ C=A\times B$ : \textcolor{red}{$n$ rows} \textcolor{red}{$q$ columns}};
\draw[blue] (A-3-1.north) -- (C-3-3.north);
\draw[blue] (A-3-1.south) -- (C-3-3.south);
\draw[blue] (B-1-3.west) -- (C-3-3.west);
\draw[blue] (B-1-3.east) -- (C-3-3.east);
\draw[<->,red](A-3-1) to[in=180,out=90] (B-1-3) node[arrow style mul] (x) {$a_{i1}\times b_{1j}$};
\draw[<->,red](A-3-3) to[in=180,out=90](B-3-3) node[arrow style mul] (y) {$a_{ik}\times b_{kj}$};
\draw[<->,red](A-3-5) to[in=180,out=90](B-5-3) node[arrow style mul] (z) {$a_{ip}\times b_{pj}$};
\draw[red,->] (x) to node[arrow style plus] {$+\raisebox{.5ex}{\ldots}+$} (y) to node[arrow style plus] {$+\raisebox{.5ex}{\ldots}+$} (z);
\draw[->,red,decorate,decoration=zigzag] (z) -- (C-3-3.north west);
\end{tikzpicture}
\end{document}
Lunula
Lunula :
[PDF]
[TEX]
\documentclass[]{article}
\usepackage{tikz}
\usetikzlibrary{through,calc}
\begin{document}
\begin{tikzpicture}[thick]
\path[draw] (-4,0) coordinate [label= left:$A$] (A)
-- ( 0,4) coordinate [label=above:$C$] (C)
-- ( 4,0) coordinate [label=right:$B$] (B)
-- cycle;
\draw [color=red] circle(4cm);
\draw[color=red,fill=black!20]
let \p1 = ($ (B) - (C) $) in
(A) arc (180:360:4cm) arc (-45:-135:{veclen(\x1,\y1)});
\foreach \point in {A,B,C} \fill [black] (\point) circle (2pt);
\end{tikzpicture}
\end{document}
RotateTriangle
RotateTriangle :
[PDF]
[TEX]
\documentclass{article}
\usepackage[usenames,dvipsnames,pdftex]{xcolor}
\usepackage{tikz,ifthen,fullpage}
\begin{document}
\thispagestyle{empty}
\newcounter{density}
\setcounter{density}{20}
\begin{tikzpicture}
\def\couleur{MidnightBlue}
\path[coordinate] ( 0 , 0) coordinate(A)
++( 60:12cm) coordinate(B)
++(-60:12cm) coordinate(C);
\draw[fill=\couleur!\thedensity] (A) -- (B) -- (C) -- cycle;
\foreach \x in {1,...,15}{ \pgfmathsetcounter{density}{\thedensity+10}
\setcounter{density}{\thedensity}
\path[coordinate] coordinate(X) at (A){};
\path[coordinate] (A) -- (B) coordinate[pos=.15](A)
-- (C) coordinate[pos=.15](B)
-- (X) coordinate[pos=.15](C);
\draw[fill=\couleur!\thedensity] (A)--(B)--(C)--cycle;}
\end{tikzpicture}
\end{document}
RotateSquare
RotateSquare :
[PDF]
[TEX]
\documentclass{article}
\usepackage[usenames,dvipsnames,pdftex]{xcolor}
\usepackage{tikz,ifthen,fullpage}
\begin{document}
\thispagestyle{empty}
\newcounter{density}
\setcounter{density}{60}
\begin{tikzpicture}
\def\a{12}
\def\couleur{MidnightBlue}
\path (0 cm,0 cm) coordinate(A)
(\a cm,0 cm) coordinate(B)
(\a cm,\a cm) coordinate(C)
(0 cm,\a cm) coordinate(D);
\draw[fill=\couleur!\thedensity] (A)--(B)--(C)--(D)--cycle;
\foreach \i in {2,...,40}
{\ifthenelse{\isodd{\i}}{ \def\couleur{MidnightBlue}}{ \def\couleur{BurntOrange}}
\pgfmathsetcounter{density}{\thedensity+5}
\setcounter{density}{\thedensity}
\path coordinate(T) at (A);
\path (A)--(B) coordinate[pos=.9] (A)
--(C) coordinate[pos=.9] (B)
--(D) coordinate[pos=.9] (C)
--(T) coordinate[pos=.9] (D);
\draw[fill=\couleur!\thedensity] (A)--(B)--(C)--(D)--cycle;}
\end{tikzpicture}
\end{document}
Blackboard
Blackboard :
[PDF]
[TEX]
\documentclass{article}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tikz,fullpage}
\usetikzlibrary{backgrounds}
\begin{document}
\thispagestyle{empty}
\tikzstyle{background rectangle}=[fill=black]
\begin{tikzpicture}[show background rectangle,line width = 1pt,color=white]
\node at (0,0) (O) {$\bullet$};
\draw (0,0) circle(5cm);
\draw (0,0) -- (-140:5) node(A) {$\bullet$};
\path[anchor=base] (O) to node[midway,sloped,above]{Radius} (A);
\draw[anchor=base] (A.center) -- +(130:5);
\draw[anchor=base] (A.center) -- +(-50:5) node[pos=.6,sloped,above] {Tangent};
\end{tikzpicture}
\end{document}
Suite
Suite récurrente :
[PDF]
[TEX]
\documentclass{article}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tikz,fullpage}
\usetikzlibrary{arrows}
\begin{document}
\thispagestyle{empty}
\begin{figure}[htbp]
\centering
\newcounter{j}
\begin{tikzpicture}[scale=10,>=latex']
\draw[color=blue,samples at={0,0.01,...,1.07}] plot (\x,{cos(\x r)});
\draw[color=green](0,0)--(1,1);
\draw[->](0,0)--(0,1) node[above]{$y$};
\draw[->](0,0)--(1,0) node[right]{$x$};
\newcounter{cnt}
\newcommand{\x}{.2}
\foreach \i in {1,...,7}{ \pgfmathcos{\x r}
\let\y\pgfmathresult
\draw[color=magenta](\x,\x)--(\x,\y)--(\y,\y);
\draw[color=orange,dotted,line width=0.8pt] (\x,\x)--(\x,0) node[below=8pt]{$u_\i$};
\pgfmathsetcounter{j}{\i+1}
\draw[color=blue,dotted,line width=0.8pt] (\x,\y)--(0,\y) node[left=8pt] {$u_\thej$};
\global\let\x\y}
\end{tikzpicture}
\caption{$f(x)=\cos (x)$}
\end{figure}
\end{document}
Ulam's Spiral
RotateSquare :
[PDF]
[TEX]
\documentclass{article}
\RequirePackage{ifthen,fullpage}
\RequirePackage{tikz}
\newcounter{cmpt}
\newcounter{next}
\newcounter{end}
\makeatletter
\newcounter{prim@r}
\newcounter{prim@a}
\newcounter{prim@n}
\newcounter{prim@d}
\newcounter{prim@b}
\newboolean{tkzaIsAPrim}
\newcommand*\primality[1]{\setboolean{tkzaIsAPrim}{true}\setcounter{prim@a}{#1} \ifthenelse{#1 = 0}{ \setboolean{tkzaIsAPrim}{false}}{ \ifthenelse{#1 = 1}{ \setboolean{tkzaIsAPrim}{false}}{ \ifthenelse{#1 = 2}{}{ \ifthenelse{#1 = 3}{}{ \ifthenelse{\isodd{#1}}{ \setcounter{prim@d}{3} \whiledo{\value{prim@a} > \value{prim@d}}{ \pgfmathsetcounter{prim@r}{mod(\theprim@a,\theprim@d)} \ifthenelse{\value{prim@r} = 0}{ \setboolean{tkzaIsAPrim}{false} \setcounter{prim@d}{\theprim@a}}{ \pgfmathaddtocounter{prim@d}{2}
} } }{ \setboolean{tkzaIsAPrim}{false} } } } } }}\makeatother
\newcommand*\ballcolor{\stepcounter{cmpt}
\primality{\value{cmpt}}
\ifthenelse{\boolean{tkzaIsAPrim}}{\colorlet{colornb}{blue!50}}{\colorlet{colornb}{orange!60}}}
\newcommand*{\ulam}[2]{\setcounter{cmpt}{#1}
\addtocounter{cmpt}{-1}
\setcounter{next}{0}
\setcounter{end}{#2}
\ballcolor
\node(place) at (0,0) {$\mathbf\thecmpt$};
\whiledo{\value{cmpt}<\value{end}}{
\foreach \i in {0,...,\thenext}
{\ballcolor
\node[above of=place] (place) {$\mathbf\thecmpt$};
}
\foreach \i in {0,...,\thenext}
{\ballcolor
\node[right of=place] (place) {$\mathbf\thecmpt$};
}
\stepcounter{next}
\foreach \i in {0,...,\thenext}
{\ballcolor
\node[below of=place] (place) {$\mathbf\thecmpt$};
}
\foreach \i in {0,...,\thenext}
{\ballcolor
\node[left of=place] (place) {$\mathbf\thecmpt$};
}
\stepcounter{next}
}
\addtocounter{next}{-1}
\foreach \i in {0,...,\thenext}
{\ballcolor
\node[above of=place] (place) {$\mathbf\thecmpt$};}
}
\begin{document}
\begin{center}
\begin{tikzpicture}
\tikzstyle{every node}=[draw, rectangle, shade, minimum size = 1.6cm, ball color = colornb, node distance = 1.6cm]
\ulam{41}{113}
\end{tikzpicture}
\end{center}
\end{document}
Alain Matthes —
al.ma@mac.com —
last modification: « 01/03/2009 » with TextMate Hosted by WebFaction.