答案1
另一种选择是元帖子包裹在 中luamplib
。用 编译它lualatex
。
点击上面的链接可以查看解释 MP 如何工作的教程和手册。
\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);
numeric u, m, m', b, b';
u = 1.44cm;
b = 3.6u; b' = b + 7/8 u;
m = -1; m' = 7/8 m;
path xx, yy;
xx = (left -- 5 right) scaled u;
yy = xx rotated 90;
numeric minx, maxx; path ff, gg;
minx = xpart point 1/16 of xx;
maxx = xpart point 15/16 of xx;
ff = (minx, minx * m + b) -- (maxx, maxx * m + b);
gg = (minx, minx * m' + b') -- (maxx, maxx * m' + b');
z0 = point 0.4 of ff;
z1 = point 0.54 of ff;
z1 0 = whatever [point 0 of gg, point 1 of gg]; x1 0 = x0;
z1 1 = whatever [point 0 of gg, point 1 of gg]; x1 1 = x1;
forsuffixes @=0, 1:
draw (x@, 0) -- z@ -- (0, y@) dashed evenly scaled 3/4;
draw z@ -- z1 @ -- (0, y1 @) dashed withdots scaled 1/2;
label.bot("$x_{" & decimal @ & "}$", (x@, 0));
label.lft("$y_{" & decimal @ & "}$", (0, y@));
label.lft("$y'_{" & decimal @ & "}$", (0, y1 @));
endfor
draw ff withcolor 2/3 red;
draw gg withcolor 3/4 blue;
drawarrow xx; drawarrow yy;
label.rt("$x$", point 1 of xx);
label.top("$y$", point 1 of yy);
dotlabel.urt("$b$", (0, b));
dotlabel.urt("$b'$", (0, b'));
draw thelabel("slope: $m=" & decimal m & "$", 7 up)
rotated angle (1, m) shifted point 2/3 of ff;
draw thelabel("slope: $m'=" & decimal m' & "$", 7 up)
rotated angle (1, m') shifted point 2/3 of gg;
endfig;
\end{mplibcode}
\end{document}
获取点的语法y'
有点棘手;但 MP 允许变量元素之间有空格,suffix
因此z0 1
对于变量来说它是一个有效的名称,而通常的z
宏魔法意味着x0 1
并y0 1
像往常一样引用 x 和 y 部分。
答案2
作为起点且仅适用于第一张图像。
\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\newcommand{\LinearEquation}
{%
\pgfmathsetmacro{\Slopef}{-1}% slope of the line 1
\pgfmathsetmacro{\Interceptf}{6}% intercept
\pgfmathsetmacro{\Slopes}{-0.9}% slope of the line 2
\pgfmathsetmacro{\Intercepts}{5}% intercept
\begin{tikzpicture}[>=latex]
\draw[->] (-1,0)--(8.3,0)node[below]{$x$};
\draw[->] (0,-1)--(0,8.3)node[left]{$y$};
\draw[very thick,red, domain=0:5] plot (\x,\Slopef*\x+\Interceptf);
\node at (0,\Interceptf)(b)[left]{$b$} ;
\def\x1{1.5}
\def\y1{\Slopef*\x1+\Interceptf}
\draw [dashed,blue](\x1,0)node[below]{$x1$}--(\x1,\y1)--(0,\y1)node[left]{$y1$};
\def\x2{3}
\def\y2{\Slopef*\x2+\Interceptf}
\draw [dashed,blue](\x2,0)node[below]{$x2$}--(\x2,\y2)--(0,\y2)node[left]{$y2^\prime$};
\draw[very thick,red, domain=0:5] plot (\x,\Slopes*\x+\Intercepts);
\node at (0,\Intercepts)(b)[left]{$b$} ;
\def\x1{1.5}
\def\y1{\Slopes*\x1+\Intercepts}
\draw [dashed,blue](\x1,0)node[below]{$x1$}--(\x1,\y1)--(0,\y1)node[left]{$y1^\prime$};
\def\x2{3}
\def\y2{\Slopes*\x2+\Intercepts}
\draw [dashed,blue](\x2,0)node[below]{$x2$}--(\x2,\y2)--(0,\y2)node[left]{$y2$};
\draw [<-](2.8,3.5)--(5,3.5)node[right]{Slope $m$};
\draw [<-](2.9,2.5)--(5,2.5)node[right]{Slope $m^\prime$};
\end{tikzpicture}%
}
\begin{document}
\LinearEquation
\end{document}