LaTeX TIKZ畫markov轉移圖(有限狀態機FSM圖)
阿新 • • 發佈:2021-01-09
作業要畫markov轉移圖,找了半天TIKZ怎麼畫FSM,程式碼記錄一下
\documentclass[a4paper,UTF8]{article}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,chains}
\begin{document}
%這裡放下面的程式碼
\end{document}
\begin{figure} \begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2cm, thick,base node/.style={circle,draw,minimum size=16pt}, real node/.style={double,circle,draw,minimum size=35pt}] \node[shape=circle,draw=black](0){0}; \node[shape=circle,draw=black](1)[right of=0 ]{1}; \node[shape=circle,draw=black](2)[right of=1 ]{2}; \node[shape=circle,draw=black](3)[right of=2 ]{3}; \path[] (0) edge [loop above]node {0.75} (0) (1) edge [loop above]node {0.75} (1) (2) edge [loop above]node {0.75} (2) (0) edge node {0.25} (1) (1) edge node {0.25} (2) (2) edge node {0.25} (3);%注意path只有一個分號 \end{tikzpicture} \end{figure}
更復雜一點的
\begin{figure} \begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2cm, thick,base node/.style={circle,draw,minimum size=16pt}, real node/.style={double,circle,draw,minimum size=35pt}] \node[shape=circle,draw=black](0){0}; \node[shape=circle,draw=black](1)[right of=0 ]{1}; \node[shape=circle,draw=black](2)[right of=1 ]{2}; \node[shape=circle,draw=black](3)[right of=2 ]{3}; \node[shape=circle,draw=black](4)[right of=3 ]{4}; \node[shape=circle,draw=black](5)[right of=4 ]{5}; \path[] (0) edge [loop above]node {0.25} (0) (0) edge [bend right=100]node {0.25} (1) (0) edge [bend right=100]node {0.25} (2) (0) edge [bend right=100]node {0.25} (3) (1) edge [loop above]node {0.25} (1) (1) edge [bend left=100]node {0.25} (2) (1) edge [bend left=100]node {0.25} (3) (1) edge [bend left=100]node {0.25} (4) (2) edge [bend right=20]node {0.25} (1) (2) edge [loop above]node {0.25} (2) (2) edge [bend right=50]node {0.25} (3) (2) edge [bend right=50]node {0.25} (4) (3) edge [bend left=40]node {0.25} (1) (3) edge [bend right=40]node {0.25} (2) (3) edge [loop above]node {0.25} (3) (3) edge [bend left=40]node {0.25} (4) (4) edge [loop above]node {0.75} (4) (4) edge node {0.25} (5); \end{tikzpicture} \end{figure}