我正在尝试绘制一个函数,直到与一条线的交点(示例中的点 a)。这是我使用的代码,但我在“let”部分给出了错误。
\documentclass[10pt,a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{intersections,calc}
\usetikzlibrary{matrix,arrows,decorations.pathmorphing}
\begin{document}
\begin{figure}
\begin{tikzpicture}
% Draw axes
\draw [<->] (0,10) node (yaxis) [left] {$x$} |- (10,0) node (xaxis) [right] {$y$};
% Draw the line
\draw [name path= line] (5,0) -- (5,8);
% Define the curve
\path [name path= curve, domain=0.75:7] plot (\x, {-1.8+8*pow(\x*0.26+0.6,-1)});
%Define intersection
\draw [name intersections={of=line and curve}] (intersection-1) coordinate (a) ;
\fill (a) circle (2pt) node[above right] {$A$};
%Draw the curve
\draw let \p1=(a) in [domain=0.75:\"What do I put in here?"] plot (\x, {-1.8+8*pow(\x*0.26+0.6,-1)});
\end{tikzpicture}
\end{figure}
\end{document}
任何帮助将非常感激!
答案1
我认为简单的解决方案
\draw [domain=0.75:5] plot ...
在这里并不感兴趣,并且该点的 x 坐标在某种程度上是“未知的”。
我建议您使用declare function
(很好)声明您的功能:
\tikzset{
declare function={
f(\x)=-1.8+8*pow(\x*0.26+0.6,-1);
}
}
通过这种方式,您现在可以根据需要多次使用函数名称,只需说f(\x)
或f(5)
等等。
当你说
\draw let \p1=(a) in ...
x 坐标\x1
以 (点) 为pt
单位,因此您需要将其转换为 中使用的 x 单位tikzpicture
,默认为1cm
;但是,您可以让 PGF 为您完成计算:
\draw let \p1=(a) in
[domain=0.75:{\x1*(2.54/72.27)}] plot (\x, {f(\x)});
完整的代码(我删除了对于问题不必要的包):
\documentclass[10pt,a4paper]{article}
\usepackage{pgfplots}
\usetikzlibrary{intersections,calc}
\usetikzlibrary{matrix,arrows,decorations.pathmorphing}
\tikzset{
declare function={
f(\x)=-1.8+8*pow(\x*0.26+0.6,-1);
}
}
\begin{document}
\begin{figure}
\begin{tikzpicture}
% Draw axes
\draw [<->] (0,10) node (yaxis) [left] {$x$} |- (10,0) node (xaxis) [right] {$y$};
% Draw the line
\draw [name path= line] (5,0) -- (5,8);
% Define the curve
\path [name path= curve, domain=0.75:7] plot (\x,{f(\x)});
%Define intersection
\draw [name intersections={of=line and curve}] (intersection-1) coordinate (a) ;
\fill (a) circle (2pt) node[above right] {$A$};
%Draw the curve
\draw let \p1=(a) in [domain=0.75:{\x1*(2.54/72.27)}] plot (\x, {f(\x)});
\end{tikzpicture}
\end{figure}
\end{document}