조각별로 정의된 함수의 색상이 잘못되었습니다.

조각별로 정의된 함수의 색상이 잘못되었습니다.

나는 이것을 계획하고 싶다.

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{calc}
\pgfplotsset{compat=newest}% <- set a compat!! (current version is 1.14)
%%%%%%%
\pgfkeys{/pgf/declare function={argsinh(\x) = ln(\x + sqrt(\x^2+1));}}
\pgfkeys{/pgf/declare function={argcosh(\x) = ln(x + sqrt(-1 + x)*sqrt(1 + x));}}
%%%%%%
\begin{document}
\begin{tikzpicture}
\begin{axis}[   
    cycle list name= color list,    
    tick align=center,
    axis lines = left,
    xmin = 0,
    xmax = 2,
    ymin = 0,
    ymax = 1.1,   
    ylabel = {$\mathopen|H(j\Omega)\mathclose|$},    
    xtick = {1,1.2},
    xticklabels = {1, $\Omega_s$},
    ytick = {0,0.1, 0.5, 1},
    yticklabels = {0, $\frac{1}{1+\varepsilon^2/k_1^2}$,$\frac{1}{1+\varepsilon^2}$,1},  
    ]

    \foreach \n in {5,6} {
    \addplot+[domain=0:1,samples=201]{1/(1+1^2*(cos(\n*(acos(\x))))^(2))};

   \addplot+[domain=1:2,samples=201]{1/(1+1^2*(cosh(\n*(argcosh(\x))))^(2))};
    }

    \addplot[black,dotted] coordinates {
        (1.2,1)
        (1.2,.1)
        (2,.1)
    };
    \addplot[black,dotted] coordinates {
        (0,.5)
        (1,.5)
        (1,0)
    };
\end{axis}
\end{tikzpicture}
\end{document}

하지만 이 네 가지 색상을 피하고 두 가지 색상 모두에 두 가지 색상만 사용해야 합니다. \n. 그러다가 새로운 단일 조각별 함수를 정의하면 이 작업을 수행할 수 있다는 것을 깨달았습니다.

%%%%%%
\begin{tikzpicture}[
\declare function={
chebyshev(\x)= (\x<=1) * (1/(1+1^2*(cos(\n*(acos(\x))))^(2)))+
     and(\x>1) * (1/(1+1^2*(cosh(\n*(argcosh(\x))))^(2)));
     }]
%%%%%% ...

\foreach \n in {5,6} {

    \addplot+[domain=0:2,samples=400]{chebyshev(\x)};

}

하지만 매번 오류가 발생하고 문제가 어디에 있는지 알 수 없습니다. 도와주세요?

답변1

문제는 acos(x)에 대해서만 정의되었으며 x \in [0,1]에 대해 플롯하려고 한다는 것입니다 x \in [0,2]. 가장 쉬운 방법은 두 가지 기능 변형을 고수하고 \pgfplotsset{cycle list shift=-1}.

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{calc}
\pgfplotsset{compat=newest}% <- set a compat!! (current version is 1.14)
%%%%%%% 
\pgfkeys{/pgf/declare function={argsinh(\x) = ln(\x + sqrt(\x^2+1));}}
\pgfkeys{/pgf/declare function={argcosh(\x) = ln(x + sqrt(-1 + x)*sqrt(1 + x));}}
%%%%%% 
\begin{document}
\begin{tikzpicture}
  \begin{axis}[   
    cycle list name= color list,    
    tick align=center,
    axis lines = left,
    xmin = 0,
    xmax = 2,
    ymin = 0,
    ymax = 1.1,   
    ylabel = {$\mathopen|H(j\Omega)\mathclose|$},    
    xtick = {1,1.2},
    xticklabels = {1, $\Omega_s$},
    ytick = {0,0.1, 0.5, 1},
    yticklabels = {0, $\frac{1}{1+\varepsilon^2/k_1^2}$,$\frac{1}{1+\varepsilon^2}$,1},  
    ]

    \foreach \n in {5,6} {
      \addplot+[domain=0:1,samples=201]{1/(1+1^2*(cos(\n*(acos(\x))))^(2))};
      \pgfplotsset{cycle list shift=-1}
      \addplot+[domain=1:2,samples=201]{1/(1+1^2*(cosh(\n*(argcosh(\x))))^(2))};
    }

    \addplot[black,dotted] coordinates {
      (1.2,1)
      (1.2,.1)
      (2,.1)
    };
    \addplot[black,dotted] coordinates {
      (0,.5)
      (1,.5)
      (1,0)
    };
  \end{axis}
\end{tikzpicture}
\end{document}

여기에 이미지 설명을 입력하세요

관련 정보