您如何绘制这样的函数?很抱歉没有为您提供解决此问题的尝试 - 我是第二天使用 Latex 的用户。非常感谢您的帮助。
\documentclass[paper=a4, fontsize=11pt]{scrartcl}
\usepackage[T1]{fontenc} % Use 8-bit encoding that has 256 glyphs
\usepackage{fourier} % Use the Adobe Utopia font for the document - comment this line to return to the LaTeX default
\usepackage[english]{babel} % English language/hyphenation
\usepackage{amsmath,amsfonts,amsthm} % Math packages
\usepackage{sectsty} % Allows customizing section commands
\allsectionsfont{\centering \normalfont\scshape} % Make all sections centered, the default font and small caps
\usepackage{fancyhdr} % Custom headers and footers
\usepackage{xfrac}
\begin{document}
\[ F_x(x) = \left\{
\begin{array}{l l}
0 & \quad \text{for $x <0$}\\
x^2 & \quad \text{$0\leq x<0.5$}\\
1-3(1-x)^2 & \quad \text{$0.5\leq x<1$}\\
1 & \quad \text{$x\geq 1$}
\end{array} \right.\]
\\
\end{document}
答案1
\documentclass{article}
\usepackage{amsmath}
\usepackage{pgfplots}
\begin{document}
\[ F_x(x) =
\begin{cases}
0 & \quad \text{for $x <0$}\\
x^2 & \quad \text{$0\leq x<0.5$}\\
1-3(1-x)^2 & \quad \text{$0.5\leq x<1$}\\
1 & \quad \text{$x\geq 1$}
\end{cases}
\]
\begin{tikzpicture}
\begin{axis}
\addplot[smooth,samples=200,domain=-2:0]{0};
\addplot[smooth,samples=200,domain=0:0.5]{x^2};
\addplot[smooth,samples=200,domain=0.5:1]{1-3*(1-x)^2};
\addplot[smooth,samples=200,domain=1:2]{1};
\end{axis}
\end{tikzpicture}
\end{document}
編輯:
实施 OP 建议的更改对我来说效果很好:
\documentclass{article}
\usepackage{amsmath}
\usepackage{pgfplots}
\begin{document}
\[ F_x(x) =
\begin{cases}
0 & \quad \text{for $x <0$}\\
2x & \quad \text{$0\leq x<0.5$}\\
6-6x & \quad \text{$0.5\leq x<1$}\\
1 & \quad \text{$x\geq 1$}
\end{cases}
\]
\begin{tikzpicture}
\begin{axis}
\addplot[smooth,samples=200,domain=-2:0]{0};
\addplot[smooth,samples=200,domain=0:0.5]{2*x};
\addplot[smooth,samples=200,domain=0.5:1]{6-6*x};
\addplot[smooth,samples=200,domain=1:2]{1};
\end{axis}
\end{tikzpicture}
\end{document}
根据要求再次编辑以创建红线和点:
\documentclass{article}
\usepackage[svgnames]{xcolor}
\usepackage{amsmath}
\usepackage{pgfplots}
\begin{document}
\[ F_x(x) =
\begin{cases}
0 & \quad \text{for $x <0$}\\
x^2 & \quad \text{$0\leq x<0.5$}\\
1-3(1-x)^2 & \quad \text{$0.5\leq x<1$}\\
1 & \quad \text{$x\geq 1$}
\end{cases}
\]
\begin{tikzpicture}
\begin{axis}
\addplot[Red,smooth,samples=200,domain=-2:0]{0};
\addplot[Red,smooth,samples=200,domain=0:0.5]{x^2};
\addplot[Red,smooth,samples=200,domain=0.5:1]{1-3*(1-x)^2};
\addplot[Red,smooth,samples=200,domain=1:2]{1};
\fill[Red] (axis cs:0,0) circle(0.5mm) (axis cs:0.5,0.25) circle(0.5mm) (axis cs:1,1) circle(0.5mm);
\end{axis}
\end{tikzpicture}
\end{document}
答案2
方法如下。如果你使用(MiKTeX) 或(TeXLive, MacTeX) 开关启动它pstricks
,就可以进行编译:pdflatex
--enable-write18
--shell-escape
\documentclass[11pt, a4paper, svgnames, pdf]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{nccmath}
\usepackage{lmodern}
\usepackage{pst-plot}
\begin{document}
\psset{unit=4cm, linewidth = 0.6pt, ticksize = -2pt 2pt}
\begin{pspicture*}(-1.6,-0.9)(1.9,1.6)
\psaxes{->}(0,0)(-1.6,-0.9)(1.9,1.6)[ $ x $, -135][ $ y $,-135]%
\uput[d](-0.05,0){0}
{\psset{linestyle = dashed,, linecolor = LightSteelBlue}
\psline(0, 0.25)(0.5, 0.25)(0.5, 0)\uput[d](0.5,0){ $ \mfrac{1}{2} $}\uput[l](0, 0.25){ $ \mfrac{1}{4} $}
\psline(0,1)(1,1)(1,0)}
\psset{linewidth = 1.5pt, linecolor =IndianRed ,plotpoints=50,plotstyle=curve, algebraic, labelsep = 0.5em}
\psline(-1.6,0)(0,0)
\psplot{0}{0.5}{x^2}
\psplot{0.5}{1}{1-3*(1-x)^2}
\psline(1,1)(2,1)
\psdots[dotsize = 3pt](0,0)(0.5, 0.25)(1,1)
\end{pspicture*}
\end{document}