数值差分网格

数值差分网格

我怎样在乳胶中绘制下面的图像? 在此处输入图片描述

答案1

像这样:

\documentclass{article}
\usepackage{tikz}
\pgfdeclarelayer{bg} 
\pgfsetlayers{bg,main}

\begin{document}
    
    \begin{tikzpicture}
        \draw (-0.5,0) -- (5,0);\draw (0,-0.5) -- (0,5);
        
        \node[text width=1cm] at (-1,2) {yi + 1\\yi\\yi-1};
        
        \node[text width=3cm] at (3,-1) {xi + 1  xi  xi-1};
        
        %red dots
        \filldraw [red] (1,1) circle (3pt);
        
        \filldraw [red] (1,3) circle (3pt);
        
        \filldraw [red] (3,1) circle (3pt);
        
        \filldraw [red] (3,3) circle (3pt);
        
        %blue dots
        \filldraw [blue] (1,2) circle (3pt);
        
        \filldraw [blue] (2,1) circle (3pt);
        
        \filldraw [blue] (2,2) circle (3pt);
        
        \filldraw [blue] (2,3) circle (3pt);
        
        \filldraw [blue] (3,2) circle (3pt);

        %grid
        \begin{pgfonlayer}{bg}  
        \draw (-1.5,0) -- (1.5,0);
        \draw (0,-1.5) -- (0,1.5);
        \draw[step=.5cm] (0.5,0.5) grid (4,4);
        \end{pgfonlayer}

\end{tikzpicture}.
    
\end{document}

在此处输入图片描述

答案2

您只需要一个\draw命令。

\documentclass[tikz,border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}[bullet/.style={circle,fill=#1,inner sep=1.5pt}] 
 \draw (0,0) grid (7,5) foreach \X in {2,3,4} {foreach \Y in {1,2,3}
 {\ifodd\numexpr\X+\Y
  \ifnum\X\Y=32
   (\X,\Y) node[bullet=blue]{}
  \else
  (\X,\Y) node[bullet=red]{}
  \fi
  \else
   (\X,\Y) node[bullet=blue]{}
  \fi 
  }}
  (-0.5,5.5) -- (-0.5,-1)
  (-1,-0.5) -- (7.5,-0.5)
  foreach \X in {-1,,+1} {(-0.6,\X+2) node[left]{$y_{j\X}$}
  (\X+3,-0.6) node[below]{$x_{i\X}$}};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容