如何限制斜坡场内地块的范围?

如何限制斜坡场内地块的范围?

有没有办法限制绘制函数的范围,这样我就不必手动输入域了?我尝试过剪辑,但这也会剪辑轴标签和斜率字段上方的描述。

\documentclass[10pt]{article}
\usepackage{amsfonts, amsmath, amssymb}
\usepackage{tikz, pgfplots}
\usetikzlibrary{calc}
\pgfplotsset{compat=1.16}

\begin{document}

\begin{tikzpicture}[scale=0.7, declare function={f(\x,\y)=(\x)+3*(\y)/(\x);}] 
\def\xmax{5} \def\xmin{-5} 
\def\ymax{5} \def\ymin{-5} 
\def\nx{10} 
\def\ny{10} 

\pgfmathsetmacro{\hx}{(\xmax-\xmin)/\nx}
\pgfmathsetmacro{\hy}{(\ymax-\ymin)/\ny}
\foreach \i in {0,...,\nx} 
\foreach \j in {0,...,\ny}{
\ifnum\i=5 \else 
\pgfmathsetmacro{\yprime}{f({\xmin+\i*\hx},{\ymin+\j*\hy})}
\draw[blue,thick, shift={({\xmin+\i*\hx},{\ymin+\j*\hy})}] 
(0,0)--($(0,0)!4mm!(.1,.1*\yprime)$);
\fi
} 

\def\yo{0.25926}
\draw[red, thick, samples=100] plot[domain=\xmin:\xmax, yrange=\ymin:\ymax] (\x,{-1*(\x)^2-(\yo)*(\x)^3}); 

\draw[->] (\xmin-.5,0)--(\xmax+.5,0) node[below right] {$x$};
\draw[->] (0,\ymin-.5)--(0,\ymax+.5) node[above left] {$y$};
\draw (current bounding box.north) node[above]
{Slope field of $y'=x+\dfrac{3y}{x}$.}; 

\end{tikzpicture}
\end{document}

在此处输入图片描述

答案1

欢迎!如果您在一定范围内进行剪辑,剪辑就会成功。这样,只有范围内的内容才会被剪辑。

\documentclass[10pt]{article}
\usepackage{amsfonts, amsmath, amssymb}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}[scale=0.7, declare function={f(\x,\y)=(\x)+3*(\y)/(\x);}] 
\def\xmax{5} \def\xmin{-5} 
\def\ymax{5} \def\ymin{-5} 
\def\nx{10} 
\def\ny{10} 

\pgfmathsetmacro{\hx}{(\xmax-\xmin)/\nx}
\pgfmathsetmacro{\hy}{(\ymax-\ymin)/\ny}
\foreach \i in {0,...,\nx} 
\foreach \j in {0,...,\ny}{
\ifnum\i=5 \else 
\pgfmathsetmacro{\yprime}{f({\xmin+\i*\hx},{\ymin+\j*\hy})}
\draw[blue,thick, shift={({\xmin+\i*\hx},{\ymin+\j*\hy})}] 
(0,0)--($(0,0)!4mm!(.1,.1*\yprime)$);
\fi
} 
\begin{scope}
\clip (\xmin,\ymin-0.5) rectangle (\xmax,\ymax);
\def\yo{0.25926}
\draw[red, thick, samples=100] plot[domain=\xmin:\xmax] (\x,{-1*(\x)^2-(\yo)*(\x)^3}); 
\end{scope}
\draw[->] (\xmin-.5,0)--(\xmax+.5,0) node[below right] {$x$};
\draw[->] (0,\ymin-.5)--(0,\ymax+.5) node[above left] {$y$};
\draw (current bounding box.north) node[above]
{Slope field of $y'=x+\dfrac{3y}{x}$.}; 

\end{tikzpicture}
\end{document}

在此处输入图片描述

还请注意,您正在加载但未使用pgfplots。您可以使用并生成箭筒图。然后剪辑将自动进行。

相关内容