Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Si vedano anche (T
E
Xample.net) e (Altermundus.com).
Database
Essendo questo il primo capitolo in cui sillustrano esempi, il codice mo-
strato volutamente prolisso: anzich usare foreach per limitarne le righe,
infatti, s preferito riportare tutte le denizioni di nodi, forme e linee di
collegamento.
z. Modello relazionale
La gura . mostra il modello relazionale di un database.
+ \documentclass{article}
u \usepackage{tikz}
\newcommand{\mysize}[1]{\footnotesize{\textbf {#1}}}
q \begin{document}
\begin{tikzpicture}[blue ,thick ,text=blue!60, scale =0.9]
o % Load Balancers
\draw[rounded corners , blue] (-0.,6) rectangle (3 ,11);
B \node at (1.5 ,10.5){ \mysize{Balancers }};
q \draw[thin](0 ,10) - -(3 ,10);
+o \node at (1.5 ,9.5){ \mysize{id\_lb}};
++ \node at (1.5 ,9){ \mysize{infodist \_lb}};
+u \node at (1.5 ,8.5){ \mysize{data\_acc\_lb}};
+ \node at (1.5 ,8){ \mysize{refresh \_lb}};
+q \node at (1.5 ,7.5){ \mysize{num\_ ports }};
+ \node at (1.5 ,7){ \mysize{state }};
+o % Switches
+ \draw[rounded corners , blue] (0 ,12) rectangle (3 ,17);
+B \node at (1.5 ,16.5){ \mysize{Switches }};
+q \draw[thin ,blue](0 ,16) - -(3 ,16);
uo \node at (1.5 ,15.5){ \mysize{id\_s}};
u+ \node at (1.5 ,15){ \mysize{managed \_s}};
uu \node at (1.5 ,14.5){ \mysize{data\_acc\_s}};
u \node at (1.5 ,14){ \mysize{refresh \_s}};
uq \node at (1.5 ,13.5){ \mysize{num\_ ports }};
u \node at (1.5 ,13){ \mysize{state }};
uo % Ips
u \draw[rounded corners , blue] (5 ,12) rectangle (8 ,17);
Capitolo z. Database
Balancers
id_lb
infodist_lb
data_acc_lb
refresh_lb
num_ports
state
Switches
id_s
managed_s
data_acc_s
refresh_s
num_ports
state
Ips
id_disp
ind_ip
vlan_id
netmask
type
id_port
Logical_links
id_disp
id_port
id_disp
id_port
weight
Figura z. Modello relazionale di un database
uB \node at (6.5 ,16.5){ \mysize{Ips }};
uq \draw[thin](5 ,16) - -(8 ,16);
o \node at (6.5 ,15.5){ \mysize{id\_disp }};
+ \node at (6.5 ,15){ \mysize{ind\_ip}};
u \node at (6.5 ,14.5){ \mysize{vlan\_id}};
\node at (6.5 ,14){ \mysize{netmask }};
q \node at (6.5 ,13.5){ \mysize{type }};
\node at (6.5 ,13){ \mysize{id\_port }};
o % Links Table
\draw[rounded corners , blue] (11 ,10) rectangle (14 ,14);
B \node at (12.5 ,13.5){ \mysize{Logical \_ links }};
q \draw[thin](11 ,13) - -(14 ,13);
qo \node at (12.5 ,12.5){ \mysize{id\_disp 1}};
q+ \node at (12.5 ,12){ \mysize{id\_port 1}};
qu \node at (12.5 ,11.5){ \mysize{id\_disp 2}};
q \node at (12.5 ,11){ \mysize{id\_port 2}};
qq \node at (12.5 ,10.5){ \mysize{weight }};
q %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
qo % Collegamenti
q %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
o
z.z. Analisi di query
qB % Punti
qq \fill[blue] (3 ,9.5) circle (2pt);
o \node (lb) at (3 ,9.5){};
+ \fill[blue] (3 ,15.5) circle (2pt);
u \node (s) at (3 ,15.5){};
\fill[blue] (8 ,15.5) circle (2pt);
q \node (ip) at (8 ,15.5){};
\fill[blue] (5 ,15.5) circle (2pt);
o \node (ip2) at (5 ,15.5){};
\fill[blue] (11 ,12.5) circle (2pt);
B \node (log_id_disp1) at (11 ,12.5){};
q \fill[blue] (11 ,11.5) circle (2pt);
oo \node (log_id_disp2) at (11 ,11.5){};
o+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ou % Linee
o \draw(lb)--(4,9.5);
oq \draw(s) - -(4 ,15.5) - -(4 ,9.5);
o \draw (4 ,12.5) - -(4.5 ,12.5) - -(4.5 ,15.5) - -(ip2);
oo \draw(ip) - -(9 ,15.5);
o \draw (9 ,12) - -(9 ,15.5);
oB \draw (10 ,11.5) - -(10 ,12.5);
oq \draw (9 ,12) - -(10 ,12);
o \draw(log_id_disp 1) - -(10 ,12.5);
+ \draw(log_id_disp 2) - -(10 ,11.5);
u \end{tikzpicture}
\end{document}
Si possono ottenere risultati decisamente migliori di questo con il pacchetto
di (Calado).
z.z Analisi di query
Si pu rappresentare gracamente lanalisi di complessit di una query con
un albero in cui le foglie sono le tabelle di partenza e la radice il risultato
nale. Molto spesso lo schema riporta anche il numero di tuple considerate
in un determinato livello e il fattore di riduzione ottenuto. La gura .
mostra un esempio in cui questi ultimi due parametri sono evidenziati con
colori diversi.
+ \documentclass{article}
u \usepackage{amsmath ,amssymb}
\usepackage{tikz}
q \begin{document}
\begin{tikzpicture}
o \node at (4,2) (a)
{$\pi_{ \text{C.CName , M.PCode , SUM (M.DurationInHours )}}$};
B \node at (4,1) (b) {$ \sigma _{ \text{AVG}(*)> 10}$};
q \node at (4,0) (c)
Capitolo z. Database
AVG()>10
GB
C.SSN, C.CName, M.PCode
p
M
M.Date111990
and M.Date31121992
C.Role=
Manager
or C.Role=
Secreatary
MP C 10
5
5 10
5
10
3
2 10
2
10
4
5 10
4
10
4
2 10
3
2 10
2
1
10
1
5
1
10
Capitolo z. Database
\usepackage{tikz}
q \definecolor{cerulean }{cmyk }{0.94 ,0.11 ,0 ,0}
\begin{document}
o \begin{tikzpicture}[mynode /. style ={circle ,draw}]
%%%%%%%%%%%
B \fill[cerulean !10](0,3) rectangle (4 ,4);
q \draw[rounded corners , thick] (0,0) rectangle (4 ,4);
+o \draw (0,3)--(4,3);
++ \node at (2 ,3.5) {Routes };
+u \node at (2 ,2.65) {Volume ($ \mathrm{m}^3$)};
+ \node at (2 ,1.9) {Weight ($ \text{kg }$)};
+q \node at (2 ,1.2) {Income };
+ \node at (2 ,0.55) {\# goods };
+o %%%%%%%%%%%
+ \node[mynode] at (2,5) (t_a) {};
+B \node [right]at (2.3 ,5) {City};
+q \node[mynode] at (2 ,5.5) (t_b) {};
uo \node[right] at (2.3 ,5.5) {Province };
u+ \node[mynode] at (2,6) (t_c) {};
uu \node [right]at (2.3 ,6) {Region };
u \node[mynode] at (2 ,6.5) (t_d) {};
uq \node [right]at (2.3 ,6.5) {State };
u \path (1.5 ,4) edge node [left]{\textsc{Dep}} (t_a);
uo \path (2.5 ,4) edge node [right]{\textsc{Dest}} (t_a);
u \path (t_a) edge (t_b);
uB \path (t_b) edge (t_c);
uq \path (t_c) edge (t_d);
o %%%%%%%%%%%
+ \node[mynode] at ( -0.5 ,2.5) (c_a) {};
u \node [above left]at ( -0.5 ,2.6) {Carrier Types };
\path (0 ,2.5) edge (c_a);
q %%%%%%%%%%%
\node[mynode] at ( -0.5 ,1.5) (g_a) {};
o \node [above left]at ( -0.5 ,1.6) {Good Category };
\path (0 ,1.5) edge (g_a);
B %%%%%%%%%%%
q \node[mynode] at (2,-0.5) (a_a) {};
qo \node [left]at (1.8 , -0.5) {Branch };
q+ \node[mynode] at (2,-1) (a_b) {};
qu \node [left]at (1.8,-1) {District };
q \path (2,0) edge (a_a);
qq \path (a_b) edge (a_a);
q %%%%%%%%%%%
qo \node[mynode] at (4.5 ,2) (r_a) {};
q \node [below]at (4.5 ,1.9) {\footnotesize{Date }};
qB \node[mynode] at (5.5 ,1) (r_b) {};
qq \node [below]at (5.5 ,0.8) {\footnotesize{Day of Months }};
o \node[mynode] at (5.5 ,3) (r_c) {};
+ \node [above]at (5.5 ,3.2) {\footnotesize{Day of Week }};
u \node[mynode] at (6,2) (r_d) {};
\node [right]at (6.3 ,2) {\footnotesize{Month }};
q \node[mynode] at (7 ,1.5) (r_e) {};
Elettronica
. Circuiti
Per realizzare i circuiti il pacchetto consigliato circuitikz di (Redaelli,
u). Un primo, facile esempio, un circuito passa-alto riportato in gura
..
+ \documentclass{article}
u \usepackage{circuitikz}
\begin{document}
q \begin{circuitikz}
\draw (-1,0) to[R,l^=$R_1$,o-](1.5 ,0);
o \draw (1,0) to [C,l^=$C_1$](3.82 , -0.005);
\draw (3.25 ,0) to[short](3.25 ,1.5);
B \draw (5 , -0.495) node[op amp]{};
q \draw (3.8 , -0.995) - -(3.8 , -2);
+o \node[ground]at (3.8 , -2){};
++ \draw (3.25 ,1.5) to [R,l^=$R_2$](6.5 ,1.5);
+u \draw (6.5 ,1.5) - -(6.5 , -0.5);
R
1
C
1
+
R
2
V
out
V
in
Figura . Circuito passa-alto
.. Circuiti
+ \draw (6.19 , -0.495)to[short ,-o](7.8 , -0.5){};
+q \draw (8.1 , -0.55) to [open ,v^<=$\, V_{out}\,$] (8.1 , -2);
+ \draw (-1.1,0) to [open ,v_<=$\,V_{in}\,$] (-1.1,-2);
+o \draw (-1,-2) to [short , o-o] (7.8 , -2);
+ \end{circuitikz}
+B \end{document}
Si noti che le etichette delle tensioni dingresso e duscita sono scritte in
modo matematico con uno spazio sottile prima e dopo: cos facendo, le
si possono distanziare dalla freccia senza troppe complicazioni, anche se
in modo non troppo elegante. In verit, tramite apposite istruzioni il
pacchetto permette di stabilire lesatta distanza fra etichetta e freccia, ma
la sintassi richiesta piuttosto complicata.
I prossimi due codici, inviati rispettivamente dagli utenti del forum g
u
It
Liverpool ed Elrond, producono entrambi lo stesso circuito appena mostrato:
un chiaro esempio di come stili di programmazione diversi (si vedano le
denizioni dei nodi assoluti e relativi) si equivalgano perfettamente.
+ % Codice di Liverpool
u \documentclass{article}
\usepackage{amsmath}
q \usepackage{circuitikz}
o \begin{document}
\begin{circuitikz}
B \draw
q (0,0) to [R, l^=$R_1$, o-] (2,0)
+o (2,0) to [C, l^=$C_1$] (5,0)
++ (5,0) node [op amp , anchor=-] (op1) {}
+u let \p{op1.out }=(op1.out) in
+ (op1.+) -| (4.9,-2)
+q (4.5 ,0) -- (4.5 ,1.5) to [R, l^=$R_2$] (7.5 ,1.5) -- (7.5,\y{op1.out})
+ (op1.out) to [short , -o] (8,\y{op1.out})
+o (0,-2) to [short , o-o] (8,-2)
+ (-0.1,0) to [open , v_<=$V_\mathrm{in}$] (-0.1,-2)
+B (8.1,\y{op1.out}) to [open , v^<=$V_\mathrm{out}$] (8.1,-2)
+q ;
uo \end{circuitikz}
u+ \end{document}
;
Capitolo . Elettronica
+ % Codice di Elrond
u \documentclass{article}
\usepackage{amsmath}
q \usepackage{circuitikz}
o \begin{document}
\begin{circuitikz}
B \draw
q (0,0) node [op amp , anchor=-] (op1) {}
+o (op1.-) to [C,l_=$C_1$] ++(-2,0) to [R,l_=$R_1$,-o] ++(-2,0)
++ (op1.-) -| ++(0 ,1.5) to [R, l^=$R_2$] ++(2 ,0) -| (op1.out)
+u (op1.out) to [short , -o] ++(1 ,0)
+ ($(op1.-) - (4 ,0)$) to [open , v_<=$V_\mathrm{in}$] ++(0,-2)
+q ($(op1.out) + (1 ,0)$) to [open , v^<=$V_\mathrm{out}$] ++(0 , -1.5)
+ to [short ,o-] ($(op1.+) - (0 ,1)$) node[shape=coordinate] (A) {}
+o (A) to[short ,-o] ++(-4,0)
+ (A) -- ++(0 , -0.5) node[ground] {}
+B (A) to (op1.+)
+q ;
uo \end{circuitikz}
u+ \end{document}
Nel prossimo esempio si sfruttano congiuntamente le risorse di TikZ e
circuitikz: la soluzione migliore per evidenziare una porzione di circuito,
infatti, usare i comandi \fill o \filldraw. La gura . il circuito a
resistenze equivalenti di un ltro a capacit commutate.
+ \documentclass{article}
u \usepackage{circuitikz}
\definecolor{burntorange }{cmyk }{0 ,0.51 ,1 ,0}
q \begin{document}
\begin{circuitikz}[scale =0.7]
o \filldraw[burntorange ,very thick ,dashed ,fill=orange !8](5.4,-0.6)--
(5.6,-0.6)--(5.6,-1)--(7.1,-1)--(7.1,-4.2)--(16.5,-4.2)--(16.5,3)--
B (5.4 ,3) - -(5.4 , -0.6);
q \node[rounded corners ,draw ,fill=orange !8] at (10 ,4)
+o {\small{Blocco non invertente }};
++ \draw[-stealth](10 ,3.5) - -(11 ,2.5);
+u %-----------------------------------------------------
+ \draw (-0.8,0) to[R,l^=$R_1$,o-] (2 ,0);
+q \draw (2 ,0) - -(2.8 ,0);
+ \node[scale =0.7,op amp] at (4 , -0.5){};
+o \draw (5.2 , -0.5) to[R,l^=$R_1$,*-*] (7.8 , -0.5);
+ \node[scale =0.7,op amp] at (9 , -1){};
+B \draw (10.2 , -1) to[R,l^=$R_4$,*-*] (12.3 , -1);
+q \node[scale =0.7,op amp] at (13.5 , -1.5){};
uo \draw (14.7 , -1.5)to [short ,-o](15.5 , -1.5);
u+ %-----------------------------------------------------
uu % morsetti a ground
u \draw (12.3 , -2) - -(12.3 , -3);
.. Circuiti
Blocco non invertente
R
1
+
R
1
+
R
4
+
R
4
C
2
R
3
C
2
R
5
V
in
V
BP
V
LP
V
LP
Figura .z Circuito equivalente di un ltro a capacit commutate
uq \draw (7.8 , -1.5) - -(7.8 , -3);
u \draw (2.8,-1)--(2.8,-3);
uo \draw(-1,-3)to [short ,o-o] (15.5 , -3);
u \node[ground] at (7.8,-3) {};
uB %-----------------------------------------------------
uq % invertente finale
o \draw (12.3 , -1) - -(12.3 ,0.5);
+ \draw (14.7 , -1.5)to[short ,*-](14.7 ,0.5);
u \draw (12.3 ,0.5) to[R,l^=$R_4$] (14.7 ,0.5);
%-----------------------------------------------------
q % invertente di mezzo
\draw (7.8 , -0.5) - -(7.8 ,1);
o \draw (10.2 , -1) - -(10.2 ,1);
\draw (7.8 ,1) to[C,l^=$C_2$] (10.2 ,1);
B %-----------------------------------------------------
q % invertente iniziale
qo \draw (2.8 ,0)to[short ,*-](2.8 ,4);
q+ \draw (5.2 , -0.5) - -(5.2 ,4);
qu \draw (2.8 ,1.5) to[R,l^=$R_3$] (5.2 ,1.5);
q \draw (2.8 ,4) to[C,l^=$C_2$] (5.2 ,4);
qq %-----------------------------------------------------
q % resistenza R_5
g
Capitolo . Elettronica
qo \draw (15.1 , -1.5) to [short ,*-] (15.1 ,6.5);
q \draw (2.3 ,0) to [short ,*-] (2.3 ,6.5);
qB \draw (2.3 ,6.5) to[R,l^=$R_5$] (15.1 ,6.5);
qq %-----------------------------------------------------
o % tensioni
+ \draw (-1,-2.9) to [open , v^>=$V_{in}$] (-1,-0.1);
u \draw (5.2 , -2.9) to [open , v>=$V_{BP}$] (5.2 , -0.6);
\draw (10.2 , -2.9) to [open , v>=$-V_{LP}$] (10.2 , -1.2);
q \draw (14.85 , -2.8) to [open , v>=$V_{LP}$] (14.85 , -1.9);
\end{circuitikz}
o \end{document}
Il pacchetto circuitikz permette di realizzare anche circuiti logici. La
gura . ne mostra alcuni esempi forniti da Claudio, un altro utente del
forum g
u
It.
+ % Codice di Claudio
u \documentclass[a4paper ,11pt]{article}
\usepackage{circuitikz}
q
\begin{document}
o
\begin{circuitikz} \draw
B (0,0)--(0,4)
q (1,0)--(1,4)
+o (0,0) node[anchor=east] {A}
++ (1,0) node[anchor=east] {B}
+u (5 ,3.0) node[or port] (myor1) {}
+
+q (0 ,3.3)to[short , *-] (myor1.in 1)
+ (1 ,2.7)to[short , *-](myor1.in 2)
+o (2 ,1.8) node[not port] (mynot 1) {}
+ (0 ,1.8)to[short , *-](mynot 1.in)
+B (2 ,0.3) node[not port] (mynot 2) {}
+q (1 ,0.3)to[short , *-](mynot 2.in)
uo (5 ,1.1) node[or port] (myor2) {}
u+ (mynot 1.out)-|(myor2.in 1)
uu (mynot 2.out)-|(myor2.in 2)
u (7.0 ,2.0) node[and port] (myand 1) {}
uq (myor1.out)-|( myand 1.in 1)
u (myor2.out)-|( myand 1.in 2);
uo \end{circuitikz}
u \begin{circuitikz} \draw
uB (0,0)--(0,4)
uq (1,0)--(1,4)
o (0,0) node[anchor=east] {A}
+ (1,0) node[anchor=east] {B}
u (5 ,3.0) node[and port] (myand 1) {}
(2 ,3.3) node[not port] (mynot 1) {}
q (5 ,1.1) node[and port] (myand 2) {}
(2 ,0.8) node[not port] (mynot 2) {}
zo
.. Circuiti
A B
A B
A B
A B
Figura . Circuiti logici realizzati con circuitikz
o (7.0 ,2.0) node[or port] (myor1) {}
(0 ,3.3)to[short , *-] (mynot 1.in)
B (mynot 1.out)--(myand 1.in 1)
q (1 ,2.7)to[short , *-](myand 1.in 2)
qo (0 ,3.3)to[short , *-](mynot 1.in)
q+ (1 ,0.8)to[short , *-](mynot 2.in)
qu (0 ,1.4)to[short , *-](myand 2.in 1)
q (mynot 2.out)--(myand 2.in 2)
qq (myand 1.out)-|(myor1.in 1)
q (myand 2.out)-|(myor1.in 2);
qo \end{circuitikz}
q
z
Capitolo . Elettronica
qB \begin{circuitikz} \draw
qq (0,0)--(0,4)
o (1,0)--(1,4)
+ (0,0) node[anchor=east] {A}
u (1,0) node[anchor=east] {B}
(5 ,3.0) node[and port] (myand 1) {}
q
(0 ,3.3)to[short , *-] (myand 1.in 1)
o (1 ,2.7)to[short , *-](myand 1.in 2)
(2 ,1.8) node[not port] (mynot 1) {}
B (0 ,1.8)to[short , *-](mynot 1.in)
q (2 ,0.3) node[not port] (mynot 2) {}
oo (1 ,0.3)to[short , *-](mynot 2.in)
o+ (5 ,1.1) node[and port] (myand 2) {}
ou (mynot 1.out)-|( myand 2.in 1)
o (mynot 2.out)-|( myand 2.in 2)
oq (7.0 ,2.0) node[or port] (myor1) {}
o (myand 1.out)-|(myor1.in 1)
oo (myand 2.out)-|(myor1.in 2);
o \end{circuitikz}
oB \begin{circuitikz} \draw
oq (0,0)--(0,4)
o (1,0)--(1,4)
+ (0,0) node[anchor=east] {A}
u (1,0) node[anchor=east] {B}
(5 ,3.0) node[or port] (myor1) {}
q (2 ,3.3) node[not port] (mynot 1) {}
(5 ,1.1) node[or port] (myor2) {}
o (2 ,0.8) node[not port] (mynot 2) {}
(7.0 ,2.0) node[and port] (myand 1) {}
B (0 ,3.3)to[short , *-] (mynot 1.in)
q (mynot 1.out)--(myor1.in 1)
Bo (1 ,2.7)to[short , *-](myor1.in 2)
B+ (0 ,3.3)to[short , *-](mynot 1.in)
Bu (1 ,0.8)to[short , *-](mynot 2.in)
B (0 ,1.4)to[short , *-](myor2.in 1)
Bq (mynot 2.out)--(myand 2.in 2)
B (myor1.out)-|( myand 1.in 1)
Bo (myor2.out)-|( myand 1.in 2);
B \end{circuitikz}
BB \end{document}
Per disegnare circuiti non occorre per forza appoggiarsi a pacchetti
esterni: TikZ stesso, infatti, corredato di alcune librerie utili allo scopo. La
gura ., che realizza un esempio inviato ancora da Claudio, lo dimostra.
+ % Codice di Claudio
u \documentclass[a4paper ,11pt]{article}
\usepackage{tikz}
q \usetikzlibrary{shapes.gates.logic.US ,shapes.gates.logic.IEC ,calc}
\tikzset{branch /. style ={fill ,shape=circle ,minimum size=3pt ,
zz
.. Circuiti
A B C
Figura .q Circuiti logici realizzati con le librerie interne
o inner sep=0pt}}
B \begin{document}
q
+o \begin{tikzpicture}
++ \node (A) at (0,0) {A};
+u \node (B) at (1,0) {B};
+ \node (C) at (2,0) {C};
+q \node[not gate US , draw] at ($(A)+(3 , -2)$) (Not1) {};
+ \node[not gate US , draw] at ($(B)+(2 , -1)$) (Not2) {};
+o \node[not gate US , draw] at ($(B)+(2 , -2.5)$) (Not3) {};
+ \node[not gate US , draw] at ($(B)+(2 , -3.4)$) (Not4) {};
+B \node[not gate US , draw] at ($(B)+(2 , -3.9)$) (Not5) {};
+q \node[and gate US , draw , logic gate inputs=nnn , anchor=input 2]
uo at ($( Not1.output -|Not2. output )+(1 ,.5)$) (and 1){};
u+ \node[and gate US , draw , logic gate inputs=nnn , anchor=input 3]
uu at ($( Not3.output -|Not4. output )+(1 , -.65)$) (and 2){};
u \node[and gate US , draw , logic gate inputs=nnn , anchor=input 3]
uq at ($( Not5. output )+(1 , -.4)$) (and 3){};
u \node[and gate US , draw , logic gate inputs=nnn , anchor=input 3]
uo at ($( and 3)+( -.4 , -1.1)$) (and 4){};
u \node[or gate US , draw , logic gate inputs=nnnn , anchor=input 2]
uB at ($( and 2)+(3 , -.5)$) (or 1){};
uq \draw (B)|-node[branch] {}( Not1. input );
o \draw (A)|-node[branch] {}( Not2. input );
+ \draw(C)|-node[branch] {}( and 1);
u \draw(Not1. output)--([xshift =0.3cm]Not1. output) |-(and1. input 3);
\draw(Not2. output)--([xshift =0.3cm]Not2. output) |-(and1. input 1);
q \draw (C)|-node[branch] {}( Not3. input );
\draw (A)|-node[branch] {}( Not4. input );
z
Capitolo . Elettronica
o \draw(Not3. output)--([xshift =0.3cm]Not3. output) |-(and2. input 1);
\draw(Not4. output)--([xshift =0.3cm]Not4. output) |-(and2. input 3);
B \draw(B)|-node[branch] {}( and 2);
q %
qo \draw(A)|-node[branch] {}( Not5. input );
q+ \draw(Not5. output)--([xshift =0.3cm]Not5. output) |-(and3. input 1);
qu \draw(B)|-node[branch] {} (and3. input 2);
q \draw(C)|-node[branch] {} (and3. input 3);
qq %
q \draw(A)|-node[branch] {}( and4. input 1);
qo \draw(B)|- node[branch] {}( and4. input 2);
q \draw(C)|- node[branch] {}( and4. input 3);
qB \draw(and1. output)--([xshift =0.5cm]and1. output) |- (or1. input 1);
qq \draw(and2. output)--([xshift =0.3cm]and2. output) |- (or1. input 2);
o \draw(and3. output)--([xshift =0.3cm]and3. output) |- (or1. input 3);
+ \draw(and4. output)--([xshift =0.5cm]and4. output) |- (or1. input 4);
u \draw (or1. output)--([xshift =0.5cm]or1. output) node[above] {};
\end{tikzpicture}
q \end{document}
.z Diagrammi di Bode
I diagrammi di Bode per modulo e fase richiedono graci ad hoc, per
i quali si consiglia di usare esclusivamente TikZ. La gura . ne mostra
una realizzazione.
dB
50
40
30
20
10
0
z
3dB
0
90
180
z
Figura . Diagrammi di Bode modulo e fase
+ \documentclass{article}
u \usepackage{textcomp}
\usepackage{tikz}
q \usepackage{amsmath ,amssymb}
\begin{document}
o \begin{center}
\begin{tikzpicture}
z
.. Grafici di segnali digitali
B \draw[dotted ,step =.5cm] (-0.5,-0.5) grid (4.5 ,3);
q \draw[->,thick] (0,-.5)--(0,3) node[above left] {$ \mathrm{dB}$};
+o \draw[->,thick] ( -.5 ,2.5) - -(4.5 ,2.5) node[right] {$ \omega $};
++ \foreach \y/\ytext in {0/ -50 ,0.5/ -40 ,1/ -30 ,1.5/ -20 ,2/ -10 ,2.5/0}
+u \draw (1pt ,\y cm) -- (-1pt ,\y cm) node[anchor=north east]
+ {$ \ytext $};
+q \draw[ultra thick ,red](0 ,2.5) - -(2 ,2.5) parabola (3.1 ,0);
+ %-----------------------------------
+o \draw[dashed ,very thick ,gray] (2.25 ,2.4) - -(2.25 ,2.6)
+ node[above ,black] {$ \omega_z$};
+B \draw[thick , stealth -,gray] (2.23 ,2.4) - -(3.1 ,2)
+q node[right ,black] {\footnotesize {$-3 \mathrm{dB }$}};
uo \end{tikzpicture}
u+ \begin{tikzpicture}
uu \draw[dotted ,step =.5cm] (-0.5,-0.5) grid (4.5 ,3);
u \draw[->,thick] (0,-0.5)--(0,3) node[above left] {$ \angle $};
uq \draw[->,thick] ( -.5 ,2.5) - -(4.5 ,2.5) node[right] {$ \omega $};
u \draw ( -.05 ,2.5) - -(.05 ,2.5);
uo \draw ( -.05 ,1.5) - -(.05 ,1.5);
u \draw ( -.05 ,0.5) - -(.05 ,0.5);
uB \node[below left] at (0 ,2.5){$0$ \textdegree };
uq \node[below left] at (0 ,1.5){$ -90$ \textdegree };
o \node[below left] at (0 ,0.5){$ -180$ \textdegree };
+ \draw[dashed ,very thick ,gray] (2.25 ,1.5) - -(2.25 ,2.5)
u node[above ,black] {$ \omega_z$};
\draw[ultra thick ,red](0 ,2.5) parabola (2.3 ,1.5);
q \draw[ultra thick ,red](4.4 ,0.5) parabola (2.3 ,1.5);
\end{tikzpicture}
o \end{center}
\end{document}
. Grafici di segnali digitali
Il prossimo esempio, realizzato nella gura .6, mostra landamento nel
tempo di due segnali digitali e la funzione XOR a essi associata. Anche in
questo caso preferibile usare esclusivamente TikZ.
+ \documentclass{article}
u \usepackage{tikz}
\usepackage{amsmath ,amssymb}
q \definecolor{processblue }{cmyk }{0.96 ,0 ,0 ,0}
\definecolor{burntorange }{cmyk }{0 ,0.51 ,1 ,0}
o \begin{document}
\begin{center}
B \begin{tikzpicture}
q \draw[thick , -stealth] (-1,0)--(11,0) node[right] {$t$};
+o \draw[thick , -stealth] (0,-0.5)--(0,2.5) node[left] {$X$};
++ \draw[very thick , processblue] (0,1.5)--(2.5,1.5)--(2.5,0)--(5,0)--
+u (5 ,1.5) - -(7.5 ,1.5) - -(7.5 ,0) - -(10 ,0) - -(10 ,1.5) - -(10.2 ,1.5) - -(10.7 ,1.5);
z
Capitolo . Elettronica
t
X
T
t
Y
t
XOR
Figura .6 Graci di segnali digitali
+ %-----------------------------------
+q % PERIODO
+ \draw[stealth -stealth] (0 ,1.75) - -(5 ,1.75);
+o \node[above] at (2.5 ,1.75) {$T$};
+ %-----------------------------------
+B \draw[thick , -stealth] (-1,-2.5)--(11,-2.5) node[right] {$t$};
+q \draw[thick , -stealth] (0,-3)--(0,-0.5) node[left] {$Y$};
uo \draw[very thick , burntorange] (0,-2.5)--(0.5,-2.5)--(0.5,-1)--
u+ (3,-1)--(3,-2.5)--(5.5,-2.5)--(5.5,-1)-- (8,-1)--(8,-2.5)--
uu (10.5,-2.5)-- (10.5 , -1) - -(10.7 , -1);
u %-----------------------------------
uq % sfasamento
u \draw[dotted ,thick] (5,0)--(5,-2.5);
uo \draw[dotted ,thick] (5.5 ,0) - -(5.5 , -1);
u \draw[stealth -stealth] (5 , -2.75) - -(5.5 , -2.75);
uB \node[below] at (5.25 , -2.75) {$\tau $};
uq %-----------------------------------
o \draw[thick , -stealth] (-1,-5)--(11,-5) node[right] {$t$};
+ \draw[thick , -stealth] (0,-6)--(0,-3)
u node[left] {\footnotesize {$ \textsc{XOR }$}};
\draw[very thick , violet](0,-3.5)--(0.5,-3.5)--(0.5,-5)--(2.5,-5)--
q (2.5,-3.5)--(3,-3.5)--(3,-5)--(5,-5)--(5,-3.5)--(5.5,-3.5)--(5.5,-5)--
(7.5,-5)--(7.5,-3.5)--(8,-3.5)--(8,-5)--(10,-5)--(10,-3.5)--
o (10.5 , -3.5) - -(10.5 , -5);
\end{tikzpicture}
B \end{center}
zo
.. Maschera di un filtro
q \end{document}
. Maschera di un filtro
Sipotizzi di voler disegnare la maschera dun ltro, cio un graco in cui
al variare della frequenza si colora la zona in cui il ltro taglier quelle
componenti armoniche. La gura . ne mostra un esempio.
dB
kHz
0
2
5
10
20
50
100
100 200 300 400 500 600 700 800
Figura .y Graco di una maschera di un ltro
+ \documentclass{article}
u \usepackage{tikz}
\usepackage{amsmath ,amssymb}
q \definecolor{burntorange }{cmyk }{0 ,0.51 ,1 ,0}
\begin{document}
o \begin{tikzpicture}
%----------------------------------------------------------------------
B % Colorazione
q %----------------------------------------------------------------------
+o \fill[fill=orange !15](1,0.5)--(1,-3.9)--(2,-3.9)--(2,0)--(8,0)--
++ (8,-3.9)--(9,-3.9)--(9,0.5)--(1,0.5);
+u \fill[fill=orange !15](3,-0.9)--(3,-6.9)--(7,-6.9)--(7,-0.9)--
+ (3 , -0.9);
+q %----------------------------------------------------------------------
+ % Griglia
+o %----------------------------------------------------------------------
+ \draw [dotted , thick ,step=1cm ,gray ,opacity =0.6] (0,-6.9) grid (10 ,1);
z;
Capitolo . Elettronica
+B \draw[dotted ,thick , gray ,opacity =0.6](0,-6.9)--(10,-6.9);
+q %----------------------------------------------------------------------
uo % Rette e label della griglia
u+ %----------------------------------------------------------------------
uu % rette
u \draw[-stealth ,thick] (1,-6.9)--(1,1) node [left] {$ \mathrm{dB}$};
uq \draw[-stealth ,thick] (0 ,0.5) - -(10 ,0.5) node[right] {$ \mathrm{kHz }$};
u % label
uo \foreach \y/\ytext in
u {0/0,-0.9/-2,-2.1/-5,-3/-10,-3.9/-20,-5.1/-50,-6/-100}
uB \draw (1.1,\y cm) -- (0.9,\y cm) node[anchor= east] {$ \ytext $};
uq \foreach \z/\ztext in {2/100 ,3/200 ,4/300 ,5/400 ,6/500 ,7/600 ,8/700 ,9/800}
o \draw (\z cm ,0.4) -- (\z cm ,0.6) node[anchor= south] {$ \ztext $};
+ %----------------------------------------------------------------------
u % Rette di delimitazione
%----------------------------------------------------------------------
q \draw[ultra thick ,dashed ,orange] (1,-3.9)--(2,-3.9)--(2,0)--(8,0)--
(8,-3.9)--(9,-3.9);
o \draw[ultra thick ,dashed ,orange] (3,-6.9)--(3,-0.9)--(7,-0.9)--(7,-6.9);
\end{tikzpicture}
B \end{document}
z
Elettromagnetismo
Questo capitolo presenta due esempi inviati da Spike, un utente del forum
g
u
It: il primo ragura la propagazione di unonda elettromagnetica nello
spazio, il secondo lo spettro delle frequenze visibili a occhio nudo.
. Propagazione di unonda elettromagnetica
La gura . mostra unonda elettromagnetica che si propaga nello spazio.
Si noti che se n evidenziata la lunghezza donda .
x
y
z
Capitolo . Elettromagnetismo
q+ \draw (4.5 ,1) -- (4.5 ,1.1) node[above] {\footnotesize \num{e14}};
qu \draw (5.5 ,1) -- (5.5 ,1.1) node[above] {\footnotesize \num{e12}};
q \draw (6.5 ,1) -- (6.5 ,1.1) node[above] {\footnotesize \num{e10}};
qq \draw (7.5 ,1) -- (7.5 ,1.1) node[above] {\footnotesize \num{e8}};
q \draw (8.5 ,1) -- (8.5 ,1.1) node[above] {\footnotesize \num{e6}};
qo \draw (9.5 ,1) -- (9.5 ,1.1) node[above] {\footnotesize \num{e4}};
q \draw (10.5 ,1) -- (10.5 ,1.1) node[above] {\footnotesize \num{e2}};
qB \draw (12 ,1) node[anchor=south east] {\small $f (\si{\hertz })$};
qq %%% lunghezze donda
o \draw (0.5 ,0) -- (0.5 , -0.1) node[below] {\footnotesize \num{e -14}};
+ \draw (1.5 ,0) -- (1.5 , -0.1) node[below] {\footnotesize \num{e -12}};
u \draw (2.5 ,0) -- (2.5 , -0.1) node[below] {\footnotesize \num{e -10}};
\draw (3.5 ,0) -- (3.5 , -0.1) node[below] {\footnotesize \num{e -8}};
q \draw (4.5 ,0) -- (4.5 , -0.1) node[below] {\footnotesize \num{e -6}};
\draw (5.5 ,0) -- (5.5 , -0.1) node[below] {\footnotesize \num{e -4}};
o \draw (6.5 ,0) -- (6.5 , -0.1) node[below] {\footnotesize \num{e -2}};
\draw (7.5 ,0) -- (7.5 , -0.1) node[below] {\footnotesize $10^0$};
B \draw (8.5 ,0) -- (8.5 , -0.1) node[below] {\footnotesize \num{e2}};
q \draw (9.5 ,0) -- (9.5 , -0.1) node[below] {\footnotesize \num{e4}};
oo \draw (10.5 ,0) -- (10.5 , -0.1) node[below] {\footnotesize \num{e6}};
o+ \draw (12 , -0.1) node[anchor=north east]
ou {\small $\lambda (\si{\meter })$};
o %%% etichette
oq \draw (0.3 ,0.5) node[anchor=west] {\small Raggi X e $\gamma $};
o \draw (3.05 ,0.5) node[anchor=west] {\small UV};
oo \draw (4.5 ,0.5) node[anchor=west] {\small IR};
o \draw (6 ,0.5) node[anchor=west] {\small $\mu$W};
oB \draw (7.1 ,0.5) node[anchor=west] {\small onde radio \phantom{p}};
oq \draw (9.1 ,0.5) node[anchor=west] {\small onde radio lunghe };
o \end{tikzpicture}
+
u \end{document}
z
Reti
Le gure di questo capitolo riproducono principalmente gra. Li si possono
realizzare in due modi, essenzialmente:
. direttamente con TikZ, denendo la posizione dei nodi: in modo
assoluto, cio specicandone a mano le coordinate, oppure in modo
relativo;
. appoggiandosi a un programma esterno come Graphviz e successiva-
mente al convertitore dot2tex per ottenere il relativo codice TikZ,
evitando cos di dover denire le posizioni dei nodi.
Questa guida considerer solo il primo dei due metodi.
. Analisi di sistemi a coda
Lanalisi di sistemi a coda si basa prevalentemente sullo studio dellevoluzio-
ne temporale, modellando il sistema attraverso catene di Markov. Il disegno
di una catena di Markov un grafo molto semplice: nel contesto della
guida tali gure sono state inserite in questo capitolo, ma unapplicazione
analoga sono le Macchine a stati niti per lelettronica.
.. Catene di Markov
La gura . mostra un esempio di catena di Markov molto semplice. Si noti
che per realizzare il descrittore dello stato s creato lo stile state, respon-
sabile delle seguenti caratteristiche: forma, diametro minimo e colorazione
dei diversi elementi del descrittore.
+ \documentclass{article}
u \usepackage{tikz}
Capitolo . Reti
1
0 2 1/4
1/2
1/2
1/4
1/2
1/2
1/2
Figura . Catena di Markov semplice
\usetikzlibrary{positioning}
q \definecolor{processblue }{cmyk }{0.96 ,0 ,0 ,0}
\begin{document}
o \begin{center}
\begin{tikzpicture}[-latex ,auto ,node distance =4cm and 5cm ,on grid ,
B semithick ,
q state /. style ={circle ,top color=white ,bottom color=processblue !20,
+o draw , processblue , text=blue ,minimum width =1cm}]
++ \node[state] (C) {$1$};
+u \node[state] (A) [above left=of C] {$0$};
+ \node[state] (B) [above right=of C] {$2$};
+q \path (A) edge [loop left] node[left]{$1/4$} (A);
+ \path (C) edge [bend left =25] node[below =0.15 cm]{$1/2$} (A);
+o \path (A) edge [bend right =-15 ] node[below =0.15 cm]{$1/2$} (C);
+ \path (A) edge [bend left =25 ] node[above]{$1/4$} (B);
+B \path (B) edge [bend left =15 ] node[below =0.15 cm]{$1/2$} (A);
+q \path (C) edge [bend left =15] node[below =0.15 cm]{$1/2$} (B);
uo \path (B) edge [bend right =-25 ] node[below =0.15 cm]{$1/2$} (C);
u+ \end{tikzpicture}
uu \end{center}
u \end{document}
Il prossimo esempio (gura .) mostra una catena di Markov pi complessa:
il descrittore dello stato, infatti, contiene due parametri. Nonostante il
maggior numero di nodi, levidente regolarit del disegno ha permesso di
ricorrere a un piccolo trucco per collocarli correttamente: una matrice
matematica di cinque righe e tre colonne, nella quale alcune posizioni sono
vuote (prima e terza posizione nella prima riga, per esempio). Tali elementi
nulli si ottengono lasciando uno spazio nel codice tra due separatori di
/2
/2
Capitolo . Reti
uq \path (A) edge [bend left =10] node{\footnotesize {$ \lambda /2$}} (B);
u \path (B) edge [bend left =10] node{\footnotesize {$\mu $}} (A);
uo %%
u \path (A) edge [bend left =10] node{\footnotesize {$ \lambda /2$}} (C);
uB \path (C) edge [bend left =10] node{\footnotesize {$\mu $}} (A);
uq %%%%%%%
o \path (B) edge [bend left =10] node{\footnotesize {$ \lambda $}} (D);
+ \path (D) edge [bend left =10] node{\footnotesize {$\mu $}} (B);
u %%
\path (C) edge [bend left =10] node{\footnotesize {$ \lambda $}} (D);
q \path (D) edge [bend left =10] node{\footnotesize {$\mu $}} (C);
%%%%%%%
o \path (D) edge [bend left =10] node{\footnotesize {$ \lambda /2$}} (E);
\path (E) edge [bend left =10] node{\footnotesize {$\mu $}} (D);
B %%
q \path (D) edge [bend left =10] node{\footnotesize {$ \lambda /2$}} (F);
qo \path (F) edge [bend left =10] node{\footnotesize {$\mu $}} (D);
q+ %%%%%%%
qu \path (E) edge [bend left =10] node{\footnotesize {$ \lambda $}} (G);
q \path (G) edge [bend left =10] node{\footnotesize {$\mu $}} (E);
qq %%
q \path (F) edge [bend left =10] node{\footnotesize {$ \lambda $}} (G);
qo \path (G) edge [bend left =10] node{\footnotesize {$\mu $}} (F);
q \end{tikzpicture}
qB \end{center}
qq \end{document}
..z Grafico utenti nel sistema
Nellanalisi delle code, importante capire anche come sevolve nel tempo
il numero di utenti presenti nella coda. La gura . mostra uno degli
esempi pi lunghi e complessi presentati in queste pagine, non tanto per
la particolare dicolt del codice (si tratta per lo pi di linee ed etichette
testuali), ma per lalto numero di elementi collegati tra di loro. Si noti come,
grazie alla diversa opacit delle linee e ai colori, il tutto sia perfettamente
leggibile.
Tramite foreach si potrebbe ridurre la lunghezza del codice, ma con una
gura cos complessa questo lavoro va fatto comunque a posteriori: in fase
di costruzione si preferisca sempre il buon vecchio copia e incolla per
scongiurare errori che sindividuerebbero poi a fatica.
+ \documentclass{article}
u \usepackage{tikz}
\definecolor{dandelion }{cmyk }{0 ,0.29 ,0.84 ,0}
q \definecolor{limegreen }{cmyk }{0.50 ,0 ,1 ,0}
o
.. Analisi di sistemi a coda
Tempo
Num. utenti
1
2
3
4
5
6
t
2
t
3
t
4
t
5
t
6
w
2
x
1
x
2
x
3
x
4
x
5
x
6
Figura . Rappresentazione dellevoluzione temporale del numero
di utenti in coda
\begin{document}
o \begin{center}
\begin{tikzpicture}[scale =0.9]
B % Assi
q \draw[-stealth] (0,0)--(12,0) node[right]{\scriptsize{Tempo }};
+o \draw[-stealth] (0.5 , -0.75) - -(0.5 ,5) node[left]{\scriptsize{Num. utenti }};
++ \foreach \y in {1,2,3,4}
+u \draw (0.6,\y)--(0.4,\y) node[left]{\small{\y}};
+ % ------------------%
+q % Riferimenti temporali - assi
+ \foreach \x/\xtext in {1/$ \tau _1$ ,2.25/$ \tau _2$ ,4.5/$ \tau_3$,
+o 5.7/$ \tau _4$ ,7.5/$ \tau _5$ ,10/$ \tau _6$}
+ \draw (\x ,0.1)--(\x , -0.1) node[below]{\small{\xtext }};
+B % ------------------%
+q % Evoluzione temporale della coda
uo \draw[blue ,very thick , opacity =0.4] (1,0)--(1,1)--(2.25,1)--(2.25,2)--
u+ (3 ,2)--(3,1)--(4.5,1)--(4.5,2)--(5.7,2)--(5.7,3)--(7.5,3)--(7.5,4);
uu \draw[blue ,very thick ,opacity =0.4] (7.5,4)--(8,4)--(8,3)--(9,3)--
u (9,2)--(10,2)--(10,3)--(10.5,3)--(10.5,2)--(11,2)--(11,1)--
uq (11.5 ,1) - -(11.5 ,0);
u % ------------------%
uo % Tempi di attesa ed inter -arrivo - proiezioni sull asse
u \draw[dotted] (1,1)--(1,2);
uB \draw[dotted] (2.25 ,2) - -(2.25 ,3);
uq \draw[dotted] (4.5 ,2) - -(4.5 ,3);
o \draw[dotted] (5.7 ,3) - -(5.7 ,4);
;
Capitolo . Reti
+ \draw[dotted] (7.5 ,4) - -(7.5 ,4.9);
u \draw[dotted] (10 ,3) - -(10 ,4.9);
% ------------------%
q % Tempi di interarrivo
\path[thick , limegreen , opacity =0.4,stealth -stealth] (1 ,1.5)
o edge node[sloped , above , text=black , opacity =1]
{\footnotesize {$t_2$}}(2.25 ,1.5);
B \path[thick , limegreen , opacity =0.4,stealth -stealth] (2.25 ,2.5)
q edge node[sloped , above , text=black , opacity =1]
qo {\footnotesize {$t_3$}}(4.5 ,2.5);
q+ \path[thick , limegreen , opacity =0.4,stealth -stealth] (4.5 ,2.5)
qu edge node[sloped , above , text=black , opacity =1]
q {\footnotesize {$t_4$}}(5.7 ,2.5);
qq \path[thick , limegreen , opacity =0.4,stealth -stealth] (5.7 ,3.5)
q edge node[sloped , above , text=black , opacity =1]
qo {\footnotesize {$t_5$}}(7.5 ,3.5);
q \path[thick , limegreen , opacity =0.4,stealth -stealth] (7.5 ,4.35)
qB edge node[sloped , above , text=black , opacity =1]
qq {\footnotesize {$t_6$}}(10 ,4.35);
o % ------------------%
+ % Tempi di attesa
u \path[thick , dandelion , opacity =0.5,stealth -stealth] (2.25 ,1.5)
edge node[sloped , below , text=black , opacity =1]
q {\footnotesize {$w_2$}}(3 ,1.5);
% ------------------%
o % Tempi di servizio - proiezioni sull asse
\draw[dotted] (1,-0.75)--(1,-1.5);
B \draw[dotted] (3,1)--(3,-1.5);
q \draw[dotted] (8,3)--(8,-1.5);
oo \draw[dotted] (9,2)--(9,-1.5);
o+ \draw[dotted] (10.5 ,2) - -(10.5 , -1.5);
ou \draw[dotted] (11 ,1) - -(11 , -1.5);
o \draw[dotted] (11.5 ,0) - -(11.5 , -1.5);
oq % ------------------%
o % Tempi di servizio
oo \path[thick , red , opacity =0.4,stealth -stealth] (1 , -1.25)
o edge node[sloped , below , text=black , opacity =1]
oB {\footnotesize {$x_1$}}(3 , -1.25);
oq \path[thick , red , opacity =0.4,stealth -stealth] (3 , -1.25)
o edge node[sloped , below , text=black , opacity =1]
+ {\footnotesize {$x_2$}}(8 , -1.25);
u \path[thick , red , opacity =0.4,stealth -stealth] (8 , -1.25)
edge node[sloped , below , text=black , opacity =1]
q {\footnotesize {$x_3$}}(9 , -1.25);
\path[thick , red , opacity =0.4,stealth -stealth] (9 , -1.25)
o edge node[sloped , below , text=black , opacity =1]
{\footnotesize {$x_4$}}(10.5 , -1.25);
B \path[thick , red , opacity =0.4,stealth -stealth] (10.5 , -1.25)
q edge node[sloped , below , text=black , opacity =1]
Bo {\footnotesize {$x_5$}}(11 , -1.25);
B+ \path[thick , red , opacity =0.4,stealth -stealth] (11 , -1.25)
Bu edge node[sloped , below , text=black , opacity =1]
Capitolo . Reti
+ \documentclass{article}
u \usepackage{tikz}
\definecolor{royalblue }{cmyk }{1 ,0.50 ,0 ,0}
q \definecolor{cerulean }{cmyk }{0.94 ,0.11 ,0 ,0}
\definecolor{violet }{cmyk }{0.79 ,0.88 ,0 ,0}
o \begin{document}
\begin{center}
B \begin{tikzpicture}
q [state 1/. style ={circle ,top color=white ,bottom color=orange !40,draw ,
+o violet ,minimum width =1cm},
++ state 2/. style ={circle ,top color=white ,bottom color=cerulean !40,draw ,
+u royalblue ,minimum width =1cm}
+ ]
+q % Nodi
+ \foreach \xa/\texta in {{0 ,2}/1 ,{1 ,0}/6 , {4 ,2}/7}
+o \node[state1] (\texta) at (\xa) {\texta };
+ \foreach \xb/\textb in {{2.5 ,1.2}/4 ,{5 ,0.2}/3 ,{6 ,1.8}/2 ,{7 ,0.7}/5}
+B \node[state2] (\textb) at (\xb) {\textb };
+q % Canali
uo \path[-latex , thick , red] (1) edge (7);
u+ \path[-latex , thick , red] (5) edge (3);
uu \path[-latex , thick , blue] (1) edge (6);
u \path[-latex , thick , blue] (5) edge (4);
uq \path[-latex , thick , blue] (5) edge (2);
u \end{tikzpicture}
uo \end{center}
u \end{document}
. Sistemi PzP
Si presentano qui tre esempi attinenti i sistemi Peer-to-Peer (PP). La
gura . mostra come in un sistema PP topologia logica e sica siano
dierenti (lesempio tratto da (Fiandrino, ud)). Si noti che le legende
hanno lo stesso colore dei relativi nodi. Per denire il nodo cloud (nuvola)
s usata la libreria shapes e leetto rilievo garantito dallopacit delle
linee verticali.
z
.. Sistemi PzP
PzP System Topology
Overlay Network
Physical Network
Figura .y Topologia logica e sica in un sistema PP
+ \documentclass{article}
u \usepackage{tikz}
\usetikzlibrary{shapes}
q \definecolor{pinegreen }{cmyk }{0.92 ,0 ,0.59 ,0.25}
\definecolor{royalblue }{cmyk }{1 ,0.50 ,0 ,0}
o \definecolor{lavander }{cmyk }{0 ,0.48 ,0 ,0}
\definecolor{violet }{cmyk }{0.79 ,0.88 ,0 ,0}
B \begin{document}
q \begin{center}
+o \tikzset{cblue /. style ={circle , draw , thin ,fill=cyan!20, scale =0.8}}
++ \tikzset{qgre/. style ={rectangle , draw , thin ,fill=green !20, scale =0.8}}
+u \tikzset{rpath /. style ={ ultra thick , red , opacity =0.4}}
+ \tikzset{legend_isps/. style ={rectangle , rounded corners , thin ,
+q fill=gray!20, text=blue , draw}}
+
+o \tikzset{legend_overlay /. style ={rectangle , rounded corners , thin ,
+ top color= white ,bottom color=green !25,
+B minimum width =2.5cm , minimum height =0.8cm ,
+q pinegreen }}
uo \tikzset{legend_phytop /. style ={rectangle , rounded corners , thin ,
u+ top color= white ,bottom color=cyan!25,
uu minimum width =2.5cm , minimum height =0.8cm ,
u royalblue }}
uq \tikzset{legend_general /. style ={rectangle , rounded corners , thin ,
u top color= white ,bottom color=lavander !25,
uo minimum width =2.5cm , minimum height =0.8cm ,
u violet }}
uB \begin{tikzpicture}[auto , thick]
uq
Capitolo . Reti
o %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ % Nuvola
u \node[cloud , fill=gray!20, cloud puffs =16, cloud puff arc= 100,
minimum width =7cm , minimum height =2.5cm , aspect =1] at (0,0) {};
q
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
o % Nodi - livello fisico
\foreach \place/\x in {{( -2.5 ,0.3)/1} , {( -1.75 , -0.55)/2} ,{( -1.2 ,0.55)/3} ,
B {( -0.75 , -0.7)/4} , {( -0.25 ,0)/5} , {(0.25 ,0.7)/6} , {(0.75 , -0.3)/7} ,
q {(1.5 ,0)/8} ,{(2.5 ,0.4)/9}}
qo \node[cblue] (a\x) at \place {};
q+
qu %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
q % Collegamenti - livello fisico
qq \path[thin] (a1) edge (a2);
q \path[thin] (a1) edge (a3);
qo \path[thin] (a2) edge (a3);
q \path[thin] (a3) edge (a6);
qB \path[thin] (a2) edge (a4);
qq \path[thin] (a5) edge (a6);
o \path[thin] (a5) edge (a4);
+ \path[thin] (a5) edge (a2);
u \path[thin] (a5) edge (a7);
\path[thin] (a6) edge (a7);
q \path[thin] (a6) edge (a9);
\path[thin] (a6) edge (a8);
o \path[thin] (a8) edge (a9);
\path[thin] (a7) edge (a8);
B
q %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
oo % Nodi - livello logico
o+ \foreach \placeov/\i in {{( -2.5 ,2.3)/1} ,{( -1.75 ,1.45)/2} ,{( -1.2 ,2.55)/3} ,
ou {( -0.75 ,1.3)/4} , {( -0.25 ,2)/5} , {(0.25 ,2.7)/6} , {(0.75 ,1.7)/7} ,
o {(1.5 ,2)/8} ,{(2.5 ,2.4)/9}}
oq \node[qgre] (b\i) at \placeov {};
o
oo %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
o % Collegamenti - livello logico
oB \path[thin] (b1) edge (b2);
oq \path[thin] (b2) edge (b4);
o \path[thin] (b4) edge (b5);
+ \path[thin] (b5) edge (b7);
u \path[thin] (b4) edge (b3);
\path[thin] (b7) edge (b8);
q \path[thin] (b8) edge (b9);
\path[thin] (b9) edge (b6);
o \path[thin] (b6) edge (b3);
\path[thin] (b3) edge (b1);
B \path[thin] (b5) edge (b8);
q \path[thin] (b5) edge (b3);
Bo \path[thin] (b5) edge (b6);
B+
.. Sistemi PzP
Bu %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
B % Collegamenti fra i due livelli
Bq \foreach \i in {1 ,... ,9}
B \path[rpath] (a\i) edge (b\i);
Bo
B %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BB % Legenda
Bq \node[legend_general] at (0 ,4){ \textsc{P2P System Topology }};
qo \node[legend_overlay] at (6 ,2){ \textsc{Overlay Network }};
q+ \node[legend_phytop] at (6 ,0){ \textsc{Physical Network }};
qu
q \end{tikzpicture}
qq \end{center}
q \end{document}
La gura .S mostra uno schema con i passaggi attraverso cui un le
diventa un torrent e un utente A pu richiederne il download.
A
.torrent Website
Tracker
. upload
. richiesta
. download .torrent
. contatto
. lista di peers
Figura .B Passaggi per distribuire un torrent
Il relativo codice :
+ \documentclass{article}
u \usepackage{tikz}
\usetikzlibrary{positioning}
q \definecolor{burntorange }{cmyk }{0 ,0.51 ,1 ,0}
\definecolor{processblue }{cmyk }{0.96 ,0 ,0 ,0}
o \begin{document}
\begin{center}
B \begin{tikzpicture}[
q peer/. style ={circle , draw=blue , fill=processblue !20,
Capitolo . Reti
+o minimum width =0.05 cm},
++ mynode /. style ={rectangle , draw , rounded corners ,
+u minimum width =1cm , minimum height =0.75 cm},
+ auto , node distance= 4cm]
+q \node[mynode] (A) at (0,0) {};
+ \node[peer , below of= A] (B) {A};
+o \node[mynode , right of=A] (C) {};
+ \node[mynode , below of =C] (D) {};
+B %%
+q \node[right= 0.4cm of C] {. torrent };
uo \node[left= 0.4cm of A] {\textsc{Website }};
u+ \node[right= 0.4cm of D] {\textsc{Tracker }};
uu %---------------
u \path[-latex , red] (C) edge[]
uq node {1. upload} (A);
u \path[-latex , blue] (B) edge[bend right]
uo node[swap]{2. richiesta} (A);
u \path[-latex ,blue] (A) edge[bend right]
uB node[swap]{3. download .torrent} (B);
uq \path[-latex , burntorange] (B) edge[bend right]
o node[swap] {4. contatto} (D);
+ \path[-latex , burntorange] (D) edge[bend right]
u node[swap] {5. lista di peers} (B);
\end{tikzpicture}
q \end{center}
\end{document}
La gura . mostra inne i vicini di primo e secondo livello di un
utente. Anche in questo caso la diversa colorazione fondamentale per la
corretta lettura del disegno.
Ecco il relativo codice:
+ \documentclass{article}
u \usepackage{tikz}
\usetikzlibrary{positioning}
q \definecolor{burntorange }{cmyk }{0 ,0.51 ,1 ,0}
\definecolor{royalblue }{cmyk }{1 ,0.50 ,0 ,0}
o \definecolor{lavander }{cmyk }{0 ,0.48 ,0 ,0}
\begin{document}
B \begin{center}
q \def \lav{lavander !90} \def \oran{orange !30} \def \cya{cyan !50}
+o \begin{tikzpicture}
++ [auto , thick ,
+u cnode /. style ={draw ,circle ,violet ,bottom color=\lav , top color= white ,
+ minimum width =15pt},
+q onode /. style ={draw ,circle ,burntorange , left color=\oran ,
+ minimum width =15pt},
+o snode /. style ={draw ,circle ,royalblue , top color=white , bottom color=\cya ,
+ minimum width =15pt}
+B ]
o
.. Sistemi PzP
Figura .g Vicini di primo e secondo livello di un utente. In arancione
lutente di riferimento, in azzurro i vicini di primo livello
e in lilla quelli di secondo
+q \foreach \place/\name in {{(0 , -1)/a}, {(2 ,0)/b}, {(0 ,2)/d}, {(-2,0)/e}}
uo \node[snode] (\name) at \place {};
u+ \node[onode] (c) at (2,2) {};
uu \foreach \source/\dest in {a/b, a/c, c/e, b/c, c/d,a/e,d/e}
u \path (\source) edge (\dest );
uq %%%%%%%
u \foreach \pos/\i in {above left/1, left/2, below left /3}
uo \node[cnode , \pos= of e] (e\i) {};
u \foreach \speer/\peer in {e/e1,e/e2,e/e3}
uB \path (\speer) edge (\peer );
uq %
o \foreach \pos/\i in {above right/1, right/2, below right /3}
+ \node[cnode , \pos= of b ] (b\i) {};
u \foreach \speer/\peer in {b/b1,b/b2,b/b3}
\path (\speer) edge (\peer );
q %
\node[cnode , above of=d] (d1){};
o \path (d) edge (d1);
%
B \foreach \pos/\i in {below left/1, below /2}
q \node[cnode , \pos =of a ] (a\i) {};
qo \foreach \speer/\peer in {a/a1,a/a2}
q+ \path (\speer) edge (\peer );
qu \end{tikzpicture}
q \end{center}
qq \end{document}
;
Teoria dei segnali
Questo capitolo presenta alcuni esempi, prodotti sia con il solo TikZ sia
con il pacchetto pgfplots. Si mostrer inoltre come esportare un graco
prodotto con MATLAB in codice TikZ tramite la libreria matlab2tikz.
o. Segnali a tempo continuo
La gura 6. mostra il graco qualitativo del segnale
x(t) = Ae
t
t
x(t)
A
Figura 6. Graco qualitativo del segnale a tempo continuo x(t)
+ \documentclass{article}
u \usepackage{tikz}
\begin{document}
q \begin{center}
\begin{tikzpicture}[domain =0:4]
o \draw[-stealth ,thick] (-0.9,0) -- (4.2 ,0) node[below] {$t$};
\draw[-stealth ,thick] (0 , -0.75) -- (0,2) node[left] {$x(t)$};
B \node [left] at (0,1) {$A$};
q \draw[very thick ,red] plot (\x ,{exp(-\x)}) ;
o.. Segnali a tempo continuo
+o \end{tikzpicture}
++ \end{center}
+u \end{document}
La gura 6. mostra lo spettro di frequenza del seguente segnale nel
dominio del tempo
y(t) = x(t) [1 + cos (2f
0
t) + cos (2Nf
0
t)]
dove x(t) un segnale strettamente limitato in banda B.
f
Y (f)
f
0
B B N f
0
Figura 6.z Graco qualitativo del segnale Y (f)
+ \documentclass{article}
u \usepackage{tikz}
\begin{document}
q \begin{center}
\begin{tikzpicture}
o \draw[-stealth ,thick] (-5,0) -- (5.5 ,0) node[below] {$f$};
\draw[-stealth ,thick] (-3.8,-0.8) -- (-3.8,2) node[left] {$Y(f)$};
B %%%%%%%%%%%%%%%%%%%%%%%%%%%
q \draw[very thick] (0,1) arc (90:0:1 and 1);
+o \draw[very thick] (-1,0) arc (0:90: -1 and 1);
++ \draw[thick ,dotted] (0,0)--(0,1);
+u \node [below ] at (0,0) {$f_0$};
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%
+q \draw[very thick] (-3.8,1) arc (90:0:1 and 1);
+ \draw[very thick] (-4.8,0) arc (0:90: -1 and 1);
+o \node [below ] at (-5,0) {$-B$};
+ \node [below ] at (-2.8,0) {$B$};
+B %%%%%%%%%%%%%%%%%%%%%%%%%%%
+q \draw[very thick] (3.8 ,1) arc (90:0:1 and 1);
uo \draw[very thick] (2.8 ,0) arc (0:90: -1 and 1);
u+ \draw[thick ,dotted] (3.8 ,0) - -(3.8 ,1);
uu \node [below ] at (3.8 ,0) {$N\,f_0$};
u \end{tikzpicture}
uq \end{center}
u \end{document}
g
Capitolo o. Teoria dei segnali
o.z Sequenze numeriche
La gura 6. mostra una possibile rappresentazione graca della sequenza
numerica
x(n) = (6 n) [u(n) u(n 6)]
n
x(n)
0
6
Figura 6. Graco sequenza numerica x(n)
+ \documentclass{article}
u \usepackage{tikz}
\begin{document}
q \begin{center}
\begin{tikzpicture}[ycomb ,mark=*]
o \draw[-stealth ,thick] (-1,0) -- (4.2 ,0) node[below] {$n$};
\draw[-stealth ,thick] (0,-0.5) -- (0,4) node[left] {$x(n)$};
B %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
q \node[below left] at (0 , -0.1){$0$};
+o \foreach \x/\xtext in {0.5/$1$ ,1/$2$ ,1.5/$3$ ,2/$4$ ,2.5/$5$}
++ \draw (\x cm ,0)--(\x cm , -0.1) node[below] {$ \xtext $};
+u %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+ \foreach \y/\ytext in {0.5/$1$ ,1/$2$ ,1.5/$3$ ,2/$4$ ,2.5/$5$ ,3/$6$}
+q \draw (0,\y cm)--(-0.1,\y cm) node[left] {$ \ytext $};
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+o \draw[dotted](0 ,0.5) - -(2.5 ,0.5);
+ \draw[dotted](0,1)--(2,1);
+B \draw[dotted](0 ,1.5) - -(1.5 ,1.5);
+q \draw[dotted](0,2)--(1,2);
uo \draw[dotted](0 ,2.5) - -(.5 ,2.5);
u+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
uu \draw[color=red ,line width =1.5pt] plot coordinates {(0 ,3) (.5 ,2.5)
u (1,2) (1.5 ,1.5) (2,1) (2.5 ,0.5)};
o
o.z. Sequenze numeriche
uq \end{tikzpicture}
u \end{center}
uo \end{document}
La gura 6. mostra una possibile realizzazione graca del sistema con
relazione dingresso-uscita (x(n)-y(n))
y(n) = x(n) + sin [a x(n 3)] + 0.5 y(n 1)
Si noti la suddivisione cromatica del disegno in due blocchi.
z
3
sin( )
z
1
x(n) y(n)
a
1/2
Figura 6.q Realizzazione graca della sequenza y(n)
+ \documentclass{article}
u \usepackage{tikz}
\definecolor{burntorange }{cmyk }{0,0.5,1,1,0}
q \definecolor{royalblue }{cmyk }{1 ,0.50 ,0 ,0}
\begin{document}
o \begin{center}
\begin{tikzpicture}
B [blocco /. style ={rectangle ,thick ,draw ,rounded corners}]
q \filldraw[draw ,royalblue ,fill=royalblue !15,very thick ,dashed](-1,1)--
+o (-1,-2.5)--(3,-2.5)--(3,1)--(-1,1);
++ \filldraw[draw ,burntorange ,fill=orange !15,very thick ,dashed](3.4,1)--
+u (3.4,-2.5)--(8,-2.5)--(8,1)--(3.4,1);
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+q \draw[-stealth ,thick] (0,0)--(2,0) node[right]{$ \oplus $};
+ \draw[-stealth ,thick] (1,0)--(1,-0.5) node[blocco ,below]{$z^{ -3}$};
+o \draw[-stealth ,thick] (1,-1.1)--(1,-1.6) node[below]{$ \otimes $};
+ \draw[-stealth ,thick] (1.2 , -1.875) - -(1.8 , -1.875)
+B node[blocco ,right] {$\sin(\ ,)$};
+q \draw[-stealth ,thick] (2.3 , -1.55) - -(2.3 , -0.3);
uo %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
u+ \draw[-stealth ,thick] (2.6,0)--(4,0) node[right]{$ \oplus $};
uu \draw[-stealth ,thick] (4.6 ,0) - -(7 ,0);
u %%%%%%%%%%%%%%%%%%%%%%%
Meccanica
Questo capitolo presenta alcuni esempi inviati da Spike.
;. Solido di Cauchy
La gura gura . mostra il solido di Cauchy, usato nella dimostrazione
del teorema omonimo. Esso aerma che per ricavare il vettore tensione in
un punto P di un corpo di forma qualsiasi (una sfera, nella gura) rispetto
a qualsiasi giacitura ( n, nella gura) basta conoscere il vettore tensione
su tre superci perpendicolari tra loro ( e
1
, e
2
, e
3
). Le quattro superci
che delimitano lintorno del punto P formano un tetraedro (il tetraedro di
Cauchy, come viene altrimenti chiamato questo solido).
P
x
y
z
e
1
e
2
e
3
n
A
1
A
2
A
3
A
Figura y. Il solido di Cauchy
;.z. Prove di trazione
+ % Codice di Spike
u \documentclass[a4paper ,11pt]{article}
\usepackage{tikz}
q \begin{document}
\begin{tikzpicture}[y={(1cm ,0cm)}, x={( -0.5cm ,-0.5cm)},
o z={(0cm ,1cm)}] % sistema di riferimento tikz 3d
%%% corpo (sfera o forma qualsiasi)
B \draw (0,-4,1.5) circle[radius =2cm];
q \draw[fill] (0,-3.6,1) circle[radius =.04cm]
+o node[above left =.1cm] {$P$};
++ \node[circle ,draw ,dashed ,red ,thick ,minimum size =0.4cm] (o)
+u at (0,-3.6,1) {};
+ \draw[help lines ,-latex] (o) .. controls (0 , -2.2 ,0.2)
+q .. (0,-0.1,0);
+ %%% disegno sdr e versori di deformazione
+o \coordinate (O) at (0, 0, 0);
+ \draw[-latex] (O) -- (3.5, 0, 0) node [left] {$x$};
+B \draw[-latex] (O) -- (0, 3.5, 0) node [right] {$y$};
+q \draw[-latex] (O) -- (0, 0, 3.5) node [above] {$z$};
uo \draw[help lines ,-latex] (O) -- (1,0,0)
u+ node[pos=0.8, left] {$\hat{e}_1$};
uu \draw[help lines ,-latex] (O) -- (0,1,0)
u node[above] {$\hat{e}_2$};
uq \draw[help lines ,-latex] (O) -- (0,0,1)
u node[right] {$\hat{e}_3$};
uo %%% tetraedro
u \draw (2.5 ,0 ,0) -- (0 ,2.5 ,0) -- (0 ,0 ,2.5) -- cycle;
uB %%% versore n
uq \draw[dashed] (O) -- (1,1,1);
o \draw[-latex] (1,1,1) -- (2,2,2) node[above left] {$\hat{n}$};
+ %%% numerazione facce
u \draw[help lines] (0 ,0.5 ,1.5) .. controls ( -0.1 ,0.8 ,1.6) ..
(0,1,2) node[above] {$A_1$};
q \draw[help lines] (0.2 ,0 ,1.5) .. controls (0.2 , -0.2 ,1.6) ..
(0.2 , -0.4 ,2) node[above] {$A_2$};
o \draw[help lines] (2 ,0.3 ,0) .. controls (2.2 ,0.5 , -0.2) ..
(2.4 ,0.7 ,0) node[right] {$A_3$};
B \draw[help lines] (0.4 ,1.8 ,0) .. controls (0.5 ,2 ,0.2) ..
q (0.6 ,2.2 ,0) node[below] {$A$};
qo \end{tikzpicture}
q+ \end{document}
;.z Prove di trazione
La gura . mostra la classica schematizzazione di un provino per le prove
di trazione uni-assiali dei materiali. Si evidenziano la lunghezza iniziale
del campione (utile per calcolarne la deformazione, pari alla dierenza fra
Capitolo ;. Meccanica
lunghezza nale e lunghezza iniziale diviso quella iniziale) e larea della sua
sezione (utile per calcolarne lo sforzo, pari a P/A).
P P
l
0
A
Figura y.z Schematizzazione di un provino per le prove di trazione
uni-assiali
Il relativo EMC :
+ % Codice di Spike
u \documentclass[a4paper ,11pt]{article}
\usepackage{tikz}
q \begin{document}
\begin{tikzpicture}
o %%% provino
\draw (0,0) -- (1.8 ,0)
B arc[start angle =180,end angle =90, radius =0.5] -- (7.5 ,0.5)
q arc[start angle =90,end angle=0, radius =0.5] -- (9.8 ,0) --
+o (9.8 ,1.6) -- (8 ,1.6)
++ arc[start angle=0,end angle=-90, radius =0.5] -- (2.3 ,1.1)
+u arc[start angle =270,end angle =180, radius =0.5] -- (0 ,1.6)
+ -- cycle;
+q %%% carichi
+ \draw[-latex] (0 ,0.8) -- ( -0.8 ,0.8) node[above]{$P$};
+o \draw[-latex] (9.8 ,0.8) -- (10.6 ,0.8) node[above]{$P$};
+ %%% zona di allungamento
+B \draw[help lines] (2.8 ,0.8) -- (2.8 , -0.3);
+q \draw[help lines] (7 ,0.8) -- (7 , -0.3);
uo \draw[help lines ,<->] (2.8 , -0.2) -- (7,-0.2)
u+ node[fill=white ,pos =0.5]{$l_0$};
uu %%% area
u \draw[help lines] (4.9 ,0.8)
uq circle[x radius =0.1,y radius =0.3];
u \node at (4.9 ,0.8)
uo [circle ,minimum size =0.6cm ,label =80:{ \color{gray}$A$}]{};
u \begin{scope}
uB \clip (4.9 ,0.8) circle[x radius =0.1,y radius =0.3];
uq \foreach \x in {0 ,0.1 ,... ,1}
o \draw[help lines] (3.5+\x ,0) -- (5.3+\x ,1.8);
+ \end{scope}
u \end{tikzpicture}
\end{document}
o
;.. Teoria della trave
;. Teoria della trave
Questa sezione presenta quattro esempi, attinenti alla teoria della trave, di
una trave a sezione circolare sottoposta a diversi carichi notevoli.
La gura . mostra la trave sottoposta a trazione pura. Con
z
s
evidenziata la sollecitazione interna di una sezione della trave.
l
p p
z
y
z x
y
Figura y. Trave a sezione circolare sottoposta a trazione pura
+ % Codice di Spike
u \documentclass[a4paper ,11pt]{article}
\usepackage{tikz}
q \begin{document}
\begin{tikzpicture}
o %%% trave
\draw[thick] (0,0) rectangle (7 ,1);
B \draw[dashed] (8.2 ,0) -- (9.5 ,0);
q \draw[dashed] (8.2 ,1) -- (9.5 ,1);
+o \draw[thick] (9.5 ,0.5) circle[radius =0.5];
++ \draw[help lines] (0,1) -- (0 ,1.5);
+u \draw[help lines] (7,1) -- (7 ,1.5);
+ \draw[help lines , <->] (0 ,1.4) -- (7 ,1.4)
+q node[fill=white ,pos =0.5]{$l$};
+ %%% carico
+o \foreach \y in {0 ,0.2 ,... ,0.9}{
+ \draw[-latex] (0,\y) -- (-0.8,\y);
+B }
+q \draw[-latex] (0,1) -- (-0.8,1) node[above right] {$p$};
uo \foreach \y in {0 ,0.2 ,... ,0.9}{
u+ \draw[-latex] (7,\y) -- (7.8,\y);
uu }
u \draw[-latex] (7,1) -- (7.8 ,1) node[above left] {$p$};
uq \draw[help lines] (5,0) -- (5 ,1);
u %%% sollecitazione interna
uo \foreach \y in {0 ,0.2 ,... ,0.9}{
u \draw[-latex] (5,\y) -- (5.8,\y);
uB }
uq \draw[-latex] (5,1) -- (5.8 ,1) node[below right] {$ \sigma_z$};
o %%% sdr
+ \draw[help lines , ->] (0 ,0.5) -- (0,-0.5) node[left]{$y$};
;
Capitolo ;. Meccanica
u \draw[help lines , ->] (0 ,0.5) -- (1.5 ,0.5) node[above]{$z$};
\draw[help lines , ->] (9.5 ,0.5) -- (8.5 ,0.5) node[above]{$x$};
q \draw[help lines , ->] (9.5 ,0.5) -- (9.5 , -0.5) node[left]{$y$};
\end{tikzpicture}
o \end{document}
La gura . mostra la trave sottoposta a essione semplice. Con
z
s evidenziata la sollecitazione interna di una sezione della trave.
l
M
x
M
x
M
x
z
y
z x
y
Figura y.q Trave a sezione circolare sottoposta a essione semplice
+ % Codice di Spike
u \documentclass[a4paper ,11pt]{article}
\usepackage{tikz}
q \usetikzlibrary{calc}
\begin{document}
o \begin{tikzpicture}
%%% trave
B \draw[thick] (0,0) rectangle (7 ,1);
q \draw[dashed] (8.2 ,0) -- (9.5 ,0);
+o \draw[dashed] (8.2 ,1) -- (9.5 ,1);
++ \draw[thick] (9.5 ,0.5) circle[radius =0.5];
+u \draw[help lines] (0,1) -- (0 ,1.5);
+ \draw[help lines] (7,1) -- (7 ,1.5);
+q \draw[help lines , <->] (0 ,1.4) -- (7 ,1.4)
+ node[fill=white ,pos =0.5]{$l$};
+o %%% carico
+ \draw[-latex] (-0.4,0)
+B arc[radius =0.8, start angle =220,end angle =140]
+q node[above left]{$M_x$};
uo \draw[-latex] (7.4 ,0)
u+ arc[radius =0.8, start angle=-40,end angle =40]
uu node[above right]{$M_x$};
u \begin{scope}[ >=latex]
uq \draw[->>] (9.5 ,0.5) -- (8.6 ,0.5)
u node[above] {\small $M_x$};
uo \end{scope}
u %%% sollecitazione interna
uB \foreach \y in { -0.5 , -0.4 , -0.3 , -0.2 , -0.1 ,0.1 ,0.2 ,... ,0.5}{
uq \draw[-latex] (5 ,0.5+\y) -- ($(5 ,0.5)+( -2*\y ,\y)$);
o }
O
1
A
B
O
2
M
F
F
12
F
23
F
23t
1 +erf
x
dove:
x il punto in cui si valuta la funzione;
la media o valore atteso;
la varianza.
A questo punto si denisce un comando che usi la sintassi di gnuplot:
% uso: \cdf(x)( media )( varianza)
\def \cdf (#1)(#2)(#3){0.5*(1+( erf ((#1 -#2)/(#3* sqrt (2)))))}
e lo si usa nellargomento di \addplot:
\addplot[opzioni] gnuplot{[funzione -gnuplot]};
Lesempio tratto da (web, a).
+ \documentclass{article}
u \usepackage{amsmath}
\usepackage{pgfplots}
q
% uso: \cdf(x)( media )( varianza)
o \def \cdf (#1)(#2)(#3){0.5*(1+( erf ((#1 -#2)/(#3* sqrt (2)))))}%
B \DeclareMathOperator{\CDF}{cdf}
;o
.z. Un diagramma di flusso
6 4 2 0 2 4 6
0
0.2
0.4
0.6
0.8
1
x
c
d
f
(
x
)
Figura B.z Graco funzione di ripartizione variable casuale normale
q
+o \begin{document}
++ \begin{tikzpicture}
+u \begin{axis}[%
+ xlabel =$x$,
+q ylabel =$\CDF(x)$,
+ grid=major]
+o \addplot[smooth ,violet] gnuplot{\cdf(x)( -2)(1)};
+ \addplot[smooth ,red] gnuplot{\cdf(x)( -1)(1)};
+B \addplot[smooth ,orange]gnuplot{\cdf(x)(0)(1)};
+q \addplot[smooth ,green]gnuplot{\cdf(x)(1)(1)};
uo \addplot[smooth ,blue]gnuplot{\cdf(x)(2)(1)};
u+ \end{axis}
uu \end{tikzpicture}
u \end{document}
.z Un diagramma di flusso
Il diagramma di usso mostrato nella gura S. un ottimo esempio della
forza di TikZ nel gestire i riferimenti relativi, dei quali si fa massiccio uso.
Inoltre nel codice si usa la libreria calc per calcolare la posizione dei nodi.
Per esempio:
\coordinate (middle) at ($( resources.west )!0.5!( sensors.west )$);
;
Capitolo . Esempi vari
determina la posizione della coordinata middle come il punto medio fra
(resources.west) e (sensors.west). Lesempio tratto da (web, b).
Pianicazione
Risorse
Sensori
Elaborazione
Archivio Segnalazione
OR
HIS
Figura B. Diagramma di usso
+ \documentclass{article}
u \usepackage{tikz}
\usetikzlibrary{shapes ,arrows ,fit ,calc}
q \tikzset{box/. style ={draw , rectangle , rounded corners , thick ,
node distance =7em , text width =6em , text centered ,
o minimum height =3.5em}}
\tikzset{container /. style ={draw , rectangle , dashed , inner sep=2em}}
B \tikzset{line/. style ={draw , thick , -latex }}
q
+o \begin{document}
++
+u \begin{tikzpicture}[auto]
+ \node [box] (planning) {Pianificazione };
+q \node [box , below of=planning] (resources) {Risorse };
+ \node [box , below of=resources] (sensors) {Sensori };
+o \node [box , below of=sensors] (processing) {Elaborazione };
+
+B \coordinate (middle) at ($( resources.west )!0.5!( sensors.west )$);
+q \node [box , left of=middle , node distance =10em] (archive) {Archivio };
;z
.. Un metodo per evidenziare parti di testo
uo \node [box , left of=archive , node distance =10em] (reporting)
u+ {Segnalazione };
uu
u \node[container , fit=( resources) (sensors)] (or) {};
uq \node at (or.north west) [above right ,node distance =0 and 0] {OR};
u
uo \node[container , fit=( archive) (reporting)] (his) {};
u \node at (his.north west) [above right ,node distance =0 and 0] {HIS};
uB
uq \path [line] (planning) -- (resources );
o \path [line] (resources) -- (sensors );
+ \path [line] (sensors) -- (processing );
u
\path [line] (archive) |- (planning );
q \path [line] (archive) |- (processing );
\path [line] (processing )--($( processing.south ) -(0 ,0.5)$)
o -| (reporting );
B \newcommand{\tikzmark}[1]{%
q \tikz[overlay ,remember picture ,baseline] \node [anchor=base] (#1) {};}
+o \begin{document}
++ \begin{align *}
+u \tikzmark{a}a_i\tikzmark{b} + b_j = 10 \\
+ c_j + d_j + \tikzmark{c}a_i\tikzmark{d} >= 30
+q \end{align *}
+
+o \begin{tikzpicture}[remember picture ,overlay]
+ \coordinate (aa) at ($(a)+(0 ,0.22)$);
+B \coordinate (bb) at ($(b)+( -0.04 ,0)$);
+q \node[draw=myframe ,line width =1pt ,fill=mybrown ,opacity =0.4, rectangle ,
uo rounded corners ,fit=(aa) (bb)] {};
u+ \coordinate (cc) at ($(c)+(0 ,0.22)$);
uu \coordinate (dd) at ($(d)+( -0.04 ,0)$);
u \node[draw=myframe ,line width =1pt ,fill=mybrown ,opacity =0.4, rectangle ,
uq rounded corners ,fit=(cc) (dd)] {};
u \end{tikzpicture}
uo \end{document}
Leetto particolarmente interessante se applicato a una presentazione:
evidenziando in tempi successivi parti diverse della stessa formula, si ottiene
una sobria animazione che aiuta a seguire lesposizione.
+ \documentclass{beamer}
u \usepackage{amsmath ,amssymb}
\usepackage{tikz}
q \usetikzlibrary{fit ,calc}
\definecolor{mybrown }{RGB }{255 ,218 ,195}
o \definecolor{myframe }{RGB }{197 ,122 ,195}
B \newcommand{\tikzmark}[1]{%
q \tikz[overlay ,remember picture ,baseline] \node [anchor=base] (#1) {};}
+o
++ \usetheme{Singapore}
+u
+ \begin{document}
+q
+ \begin{frame }{ Animare una formula}
+o \begin{equation *}
+ \tilde{Q}_{t,s} = \tikzmark{a}\sum_{k \in K} q_{k,t,s}\tikzmark{b} +
+B \tikzmark{c}\sum_{w\in W} g_{w,t,s} \tikzmark{d}
+q \end{equation *}
;
.. Matrici
uo \begin{tikzpicture}[remember picture ,overlay]
u+ \coordinate (aa) at ($(a)+(0.1 ,0.5)$);
uu \coordinate (bb) at ($(b)+( -0.1 , -0.5)$);
u \node <1>[draw=myframe ,line width =1pt ,fill=mybrown ,opacity =0.4, rectangle ,
uq rounded corners ,fit=(aa) (bb)] {};
u \coordinate (cc) at ($(c)+(0.1 ,0.5)$);
uo \coordinate (dd) at ($(d)+(0 , -0.5)$);
u \node <2>[draw=myframe ,line width =1pt ,fill=mybrown ,opacity =0.4, rectangle ,
uB rounded corners ,fit=(cc) (dd)] {};
uq \end{tikzpicture}
o \end{frame}
+ \end{document}
Il punto forte del metodo appena esposto sono le istruzioni <1> e <2>, quelle
che creano il movimento. Le gure S.(a) e S.(b) mostrano il risultato.
Animare una formula
Qt,s =
kK
qk,t,s +
wW
gw,t,s
(a) Prima parte della formula evidenziata
Animare una formula
Qt,s =
kK
qk,t,s +
wW
gw,t,s
(b) Seconda parte della formula eviden-
ziata
Figura B.q La diapositiva creata
Il punto debole, viceversa, il fatto che a una prima impressione il
riquadro colorato copre la formula rendendola meno leggibile. In realt la
macro \tikzmark, con cui stato ottenuto, ben rodata, ma ne esiste una
versione pi potente che risolve linconveniente. Chi volesse constatarne
lecacia sia nelle presentazioni sia in documenti normali, veda (Fiandrino,
uc) e (Fiandrino, ua) nellordine.
. Matrici
La libreria matrix di TikZ permette di gestire le matrici con relativa facilit:
si vedano i numerosi esempi nella documentazione del pacchetto (Tantau,
;
Capitolo . Esempi vari
uu).
Nella gura S. si illustrano alcuni passi dellaugmentation algorithm per
ottenere una matrice bistocastica la quale, scomposta grazie alla Birkho-
von Neumann decomposition, permette di determinare parametri di qualit
del servizio in sistemi input queued. Il codice relativo presenta i seguenti
aspetti notevoli:
il modo in cui lo sfondo di alcuni elementi evidenziato:
tramite comandi personali;
tramite la libreria backgrounds e un nuovo livello di sfondo;
il modo in cui si sono inserite le annotazioni accanto alla matrice;
lannidamento dellambiente tikzpicture in un ambiente matematico.
R =
0.0 0.3 0.2 0.4
0.2 0.3 0.0 0.2
0.4 0.1 0.3 0.0
0.2 0.0 0.2 0.3
u.
u.
u.S
u.
u.S
u. u. u.
=
0.0 0.4 0.2 0.4
0.2 0.4 0.0 0.2
0.4 0.2 0.4 0.0
0.2 0.0 0.2 0.4
u.S
u.S
u.S
u.S
=
0.0 0.4 0.2 0.4
0.4 0.4 0.0 0.2
0.4 0.2 0.4 0.0
0.2 0.0 0.4 0.4
Figura B. Esempi di matrici
+ \documentclass{article}
u \usepackage{amsmath}
\usepackage{xparse}
q \usepackage{tikz}
\usetikzlibrary{matrix ,backgrounds}
o \pgfdeclarelayer{myback}
\pgfsetlayers{myback ,background ,main}
;o
.. Matrici
B
q \tikzset{mycolor /. style = {line width =1bp ,color =#1}}%
+o \tikzset{myfillcolor /. style = {fill=#1,draw=black !50}}%
++
+u \NewDocumentCommand{\highlight }{O{blue !30} m m}{%
+ \draw[mycolor =#1] (#2. north west)rectangle (#3. south east);
+q }
+
+o % per eliminare spazi sovrapposti
+ \NewDocumentCommand{\fhighlight }{O{blue !30} m m}{%
+B \draw[myfillcolor =#1] ($(#2. north west )+(0.5bp ,-0.5bp)$)
+q rectangle ($(#3. south east ) -(0.5bp ,-0.5bp)$);
uo }
u+
uu \begin{document}
u \begin{align *}R = &
uq \begin{tikzpicture}[baseline=-\the \dimexpr \fontdimen 22 \textfont2\relax]
u \matrix (m)[matrix of math nodes ,left delimiter =(,right delimiter =),
uo ampersand replacement=\&]
u {
uB 0.0 \& 0.3 \& 0.2 \& 0.4\\
uq 0.2 \& 0.3 \& 0.0 \& 0.2\\
o 0.4 \& 0.1 \& 0.3 \& 0.0\\
+ 0.2 \& 0.0 \& 0.2 \& 0.3\\
u };
\begin{pgfonlayer }{ myback}
q \foreach \element in {m-1-2,m-2-2,m-3-2,m-3-3,m-4 -4}{
\fhighlight[red !30]{\element }{ \element}
o }
\end{pgfonlayer}
B %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
q \foreach \x/\xtext in {m-1 -4/0.9 ,m-2 -4/0.7 ,m-3 -4/0.8 ,m-4 -4/0.7}
qo \node[shift =(\x.east),xshift =0.75 cm](0,0) {\xtext };
q+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
qu \foreach \x/\xtext in {m-4 -1/0.8 ,m-4 -2/0.7 ,m-4 -3/0.7 ,m-4 -4/0.9}
q \node[shift =(\x.south),yshift = -0.25cm](0,0) {\xtext };
qq \end{tikzpicture}
q =
qo \begin{tikzpicture}[baseline=-\the \dimexpr \fontdimen 22 \textfont2\relax]
q \matrix (m)[matrix of math nodes ,left delimiter =(,right delimiter =),
qB ampersand replacement=\&]
qq {
o 0.0 \& 0.4 \& 0.2 \& 0.4\\
+ 0.2 \& 0.4 \& 0.0 \& 0.2\\
u 0.4 \& 0.2 \& 0.4 \& 0.0\\
0.2 \& 0.0 \& 0.2 \& 0.4\\
q };
\begin{pgfonlayer }{ myback}
o \foreach \element in {m-1-2,m-2-2,m-3-2,m-3-3,m-4 -4}{
\fhighlight{\element }{ \element}
B }
q \foreach \element in {m-2-1,m-4 -3}{
;;
Capitolo . Esempi vari
oo \fhighlight[red !30]{\element }{ \element}
o+ }
ou \end{pgfonlayer}
o %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
oq \foreach \x/\xtext in {m-1-4/1,m-2 -4/0.8 ,m-3-4/1,m-4 -4/0.8}
o \node[shift =(\x.east),xshift =0.75 cm](0,0) {\xtext };
oo %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
o \foreach \x/\xtext in {m-4 -1/0.8 ,m-4-2/1,m-4 -3/0.8 ,m-4 -4/1}
oB \node[shift =(\x.south),yshift = -0.25cm](0,0) {\xtext };
oq \end{tikzpicture}
o =\\
+ &
u \begin{tikzpicture}[baseline=-\the \dimexpr \fontdimen 22 \textfont2\relax]
\matrix (m)[matrix of math nodes ,left delimiter =(,right delimiter =),
q ampersand replacement=\&]
{
o 0.0 \& 0.4 \& 0.2 \& 0.4\\
0.4 \& 0.4 \& 0.0 \& 0.2\\
B 0.4 \& 0.2 \& 0.4 \& 0.0\\
q 0.2 \& 0.0 \& 0.4 \& 0.4\\
Bo };
B+ \begin{pgfonlayer }{ myback}
Bu \foreach \element in {m-2-1,m-4 -3}{
B \fhighlight{\element }{ \element}
Bq }
B \end{pgfonlayer}
Bo %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
B \foreach \x/\xtext in {m-1-4/1,m-2-4/1,m-3-4/1,m-4 -4/1}
BB \node[shift =(\x.east),xshift =0.75 cm](0,0) {\xtext };
Bq %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
qo \foreach \x/\xtext in {m-4-1/1,m-4-2/1,m-4-3/1,m-4 -4/1}
q+ \node[shift =(\x.south),yshift = -0.25cm](0,0) {\xtext };
qu \end{tikzpicture}
q \end{align *}
qq
q \end{document}
I comandi \hightlight e \fhighlight, deniti grazie al pacchetto xparse
evidenziano gli elementi della matrice usando due stili distinti, mycolor e
myfillcolor rispettivamente. Il primo non colora lo sfondo degli elementi
selezionati:
\tikzset{mycolor /. style = {line width =1bp ,color =#1}}%
\NewDocumentCommand{\highlight }{O{blue !30} m m}{%
\draw[mycolor =#1] (#2. north west)rectangle (#3. south east);
}
mentre il secondo s:
\tikzset{myfillcolor /. style = {fill=#1,draw=black !50}}%
;
.. Matrici
\NewDocumentCommand{\fhighlight }{O{blue !30} m m}{%
\draw[myfillcolor =#1] (#2. north west)rectangle (#3. south east);
}
Si noti che i comandi appena visti vanno inseriti in un ambiente pgfonlayer,
al quale si assegner come argomento il nuovo livello di sfondo myback:
\pgfdeclarelayer{myback} % definizione
da mettere nella giusta posizione rispetto ai due livelli background e main
predeniti in TikZ con:
\pgfsetlayers{myback ,background ,main} % posizionamento
per evitare eventuali conitti nel caso in cui per altre gure si usi il livello
background.
Quando nella costruzione di una matrice con TikZ compaiono unetichet-
ta e lopzione matrix of math nodes, gli elementi sono inseriti in modo matema-
tico e i riferimenti deniti con la sintassi etichetta-riga-colonna. Inol-
tre, per evitare problemi nel riconoscimento del carattere \& nellambiente
align*, lo si pu cambiare con lopzione ampersand replacement=simbolo.
Per inserire le somme degli elementi presenti nelle righe e nelle colonne
e per colorare lo sfondo di alcuni, si sfruttata la potenzialit del metodo
di riferimento illustrato in precedenza per accedere a singoli elementi della
matrice etichetta-riga-colonna:
\foreach \x/\xtext in {m-4-1/1,m-4-2/1,m-4-3/1,m-4 -4/1}
\node[shift =(\x.south),yshift = -0.25cm](0,0) {\xtext };
e:
\foreach \element in {m-2-1,m-4 -3}{
\fhighlight[red !30]{\element }{ \element}
}
Per inserire un ambiente tikzpicture in un ambiente matematico garan-
tendo un perfetto allineamento verticale delle righe, serve:
[baseline=-\the \dimexpr \fontdimen 22 \textfont2\relax]
Questa dimensione, illustrata in (Gregorio, u) utilissima anche quan-
do la matrice non sia lunico elemento presente nellambiente matematico.
Lesempio stato costruito facendo riferimento a (Fiandrino, u)
e (Fiandrino, ub); in particolare, (Fiandrino, ub) illustra molti
altri metodi che risolvono il problema.
;g
Bibliografia
(a).
(b).
Altermundus.com. Website. URL http://altermundus.com/index.
html.
Calado, P. tikz-er. URL http://www.assembla.com/wiki/show/
tikz-er2. Pacchetto.
Crmer, J. (u). A very minimal introduction to TikZ. URL http:
//cremeronline.com/LaTeX/minimaltikz.pdf.
Fiandrino, C. (uu). Progetto di un ltro FIR. URL
http://claudiofiandrino.altervista.org/teoria_dei_segnali/
relazione.pdf. Relazione.
(u). Tikz e matrici. URL http://www.guitex.org/home/it/
forum/5-tex-e-latex/66105-risolto-tikz-e-matrici. Forum G
U
IT.
(ua). Highlight a column in equation or math environ-
ment. URL http://tex.stackexchange.com/questions/57101/
highlight-a-column-in-equation-or-math-environment/57102#
57102. Forum TeX.StackExchange.
(ub). Highlight elements in the matrix.
URL http://tex.stackexchange.com/questions/40028/
highlight-elements-in-the-matrix/61753#61753. Forum
TeX.StackExchange.
Bibliografia
(uc). Mark a pseudocode block and insert comments near
it. URL http://tex.stackexchange.com/questions/57060/
mark-a-pseudocode-block-and-insert-comments-near-it#57073.
Forum TeX.StackExchange.
(ud). Pp topology. URL http://www.texample.net/tikz/
examples/p2p-topology/. Forum TeX.StackExchange.
Goulding, K. (u). TikZ for economists. URL http://www.slideshare.
net/kevingoulding/tikz-for-economists.
Gregorio, E. (u). Use of tikzpicture matrix in align or gather envi-
ronment. URL http://tex.stackexchange.com/questions/59658/
use-of-tikzpicture-matrix-in-align-or-gather-environment/
59660#59660. Forum TeX.StackExchange.
Nisi, R. (uu). La graca di TikZ e PGF. URL http://www.guit.sssup.
it/downloads/TikZxGuit2.pdf.
Pantieri, L. e Gordini, T. (u). Larte di disegnare graci con L
A
T
E
X.
URL www.lorenzopantieri.net/LaTeX_files/Grafici.pdf.
Redaelli, M. (u). Circuitikz. Pacchetto. Consultabile con texdoc
circuitikz.
Stacey, A. (u). How productive are you with ti-
kz? URL http://tex.stackexchange.com/questions/
52542/how-productive-are-you-with-tikz#52547. Forum
TeX.StackExchange.
Tantau, T. (uu). The TikZ and PGF Packages. URL http://
sourceforge.net/projects/pgf. Consultabile con texdoc tikz.
T
E
Xample.net. Website. URL http://www.texample.net/tikz/.
Tisseau, J. e Duma, J. (u). TikZ pour limpatient. URL http://math.
et.info.free.fr/TikZ/.
z