向绘图中添加其他坐标

向绘图中添加其他坐标

我尝试了一遍又一遍,仍然无法让它看起来像这样,特别是切线:

在此处输入图片描述

梅威瑟:(致谢希门斯

\documentclass[tikz,border=1mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usetikzlibrary{arrows.meta}

\begin{document}
\begin{tikzpicture}[
    scale=1.5,
    every node/.style={scale=0.5},
    >={Triangle[scale=0.6]}
    ]

    % Drawing the main axis:
    \draw[<->]  (0,1/0.25) node[above]{$y$} -- 
                (0,0) node[below left]{0} -- 
                (4.5,0) node[right]{$x$};
    % Drawing the main function:
    \draw[thick] plot[domain=0.28:4.4, samples=200](\x,{1/\x}) node[right]{$k^{0}$};
    % Drawing the dotted lines:
    \draw[densely dotted, thick]    (1,0) node[below]{$x^{0}$} |-
                                    (0,1) node[left]{$y^{0}$};
    % Drawing the dashed lines:
    \foreach \x in {0.55,1,1.3,2}{
        \draw[densely dashed] (0,0) -- (\x,1/\x);
    }
    % Drawing the points:
    \foreach \p in {0.45, 0.55, 1, 1.3, 2, 2.6}{
        \draw[fill=black] (\p,1/\p) circle (1pt);
    }
    % Labeling the points:
    \node[above right] (M'') at (0.45,1/0.45){$M''$};
    \node[above right] (A) at (0.55,1/0.55){$A$};
    \node[above right] at (1,1){$P$};
    \node[above right] at (1.3,1/1.3){$M$};
    \node[above right] (B) at (2,1/2){$B$};
    \node[above right] (M') at (2.6,1/2.6){$M'$};
    % Drawing the arrows:
    \draw[->] (A) -- (M'');
    \draw[->] (B) -- (M');
    \draw[->] (0.4,3.2) -- (0.55,3.2);
    \draw[->] (3.5,0.45) -- (3.65,0.45);
    % Drawing the dashed function:
    \draw[  thick, 
            xshift = 0.3cm, 
            yshift = 0.3cm, 
            dash pattern = on 10.85pt off 3pt
    ] plot[domain=0.28:4.4, samples=200](\x,{1/\x}) node[right]{$k^{1}$};
    
\end{tikzpicture}
\end{document}

答案1

要点C数学上可以找到,参见factorA函数。也可以找到点Cintersections我们必须找到X该点的值坐标坐标系(除非使用旋转坐标系,否则这并不难)。

还有第二个解决方案,在平方根之前有一个减号,但我并没有真正检查这个解决方案是否有效。我假设A> 0。b> 0,即该因子大于 1。含义¹ 始终位于⁰。

切线由这两个函数的导数决定(另一个数学解)。在 PGF/TikZ 中执行此操作并不容易,尤其是在C

XAC是它们自己的 PGFMath 函数。由于xC包含函数,因此factorA每次使用时都会计算该值,xC即使它是常量(效率不高)。

代码

\documentclass[tikz]{standalone}
\usetikzlibrary{arrows.meta, calc}
\begin{document}
\begin{tikzpicture}[
  x=2cm, y=2cm, thick, >=Triangle,
  every label/.append style={inner sep=+.15em},
  declare function={
    a = .5; b = .5; xA = .55; xB = 2; xC = factorA(xA, a, b) * xA;
    f(\x)  = 1/\x;       ft(\x) = -1/\x/\x;
    g(\x)  = 1/(\x-a)+b; gt(\x) = -1/(\x-a)/(\x-a);
    factorA(\x,\a,\b) = (sqrt(\a*\a-2*\a*\b*\x*\x+\b*\b*\x*\x*\x*\x+4*\x*\x)
                         +\a+\b*\x*\x)/(2*\x);},
  label positions/.style args={#1:#2}{label #1/.style={label={#2:##1}}},
  label positions/.list={A:right, B:above, C:right, R:above right},
  dot/.style={
    circle, inner sep=+0pt, outer sep=+0pt, minimum size=+3pt, fill,
    label #1/.try={$#1$}},
  mark on axis/.style args={#1:#2}{insert path={
    (#1) edge[densely dotted] node[at end, below] {$x_{#2}$} (#1|-0,0)
         edge[densely dotted] node[at end, left]  {$y_{#2}$} (#1-|0,0)}}
]
\draw[<->] (0,4.5) node[above]{$y$} |- (5.5,0) node[right]{$x$};
\draw[very thick, samples=200] plot[domain=.28:4.4] (\x,{f(\x)}) node[right]{$k^0$}
                           plot[domain=.28+a:4.4+a] (\x,{g(\x)}) node[right]{$k^1$};

\foreach[count=\cnt] \pnt/\fct in {A/f, B/f, C/g}
  \node[dot=\pnt] (\pnt) at (x\pnt,{\fct(x\pnt)}) {} [mark on axis=\pnt:\cnt];

\foreach \pnt/\lbl in {A/R, B/{}}
  \draw[dashed] (0,0) -- ($(0,0)!2!(\pnt)$) coordinate[label \lbl/.try=$\lbl$] ();

\foreach[/pgf/inner sep=+.15em, evaluate={\ang=atan(\fct t(x\pnt));}]
  \pnt/\lbl/\fct in {A/a/f, B/{}/f, C/c/g}
  \draw[dashed, shift=(\pnt)](\ang+180:1) node[above left] {$\lbl$}
                          -- (\ang    :1) node[below]      {$\lbl$};
\end{tikzpicture}
\end{document}

输出

在此处输入图片描述

答案2

无论如何,这里有一个变体我对你另一个问题的回答,同样在元帖子在此处输入图片描述

这个示例展示了处理pair变量的另一种方式——z符号允许您使用它们而无需声明它们——以及在曲线上的某个点绘制切线的函数。和以前一样,您需要使用 来编译它lualatex

\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);
    path xx, yy, ff, k[];
    xx = 20 left -- 300 right;
    yy = xx rotated 90;
    ff = (1, 1) {dir -45} for x = 2 upto 5: .. (x, 1/x) endfor;
    ff := reverse ff reflectedabout(origin, (1,1)) & ff;
    k0 = ff scaled 280/5; 
    k1 = subpath (2, 6) of ff scaled 280/3;

    numeric a, b, c;
    a = 3.4; b = 5.1;
    z.A = point a of k0;
    z.B = point b of k0;
    z.R = 2.4 z.A;
    z.S = 2 z.B;

    (c, whatever) = k1 intersectiontimes (origin -- z.R);
    z.C = point c of k1;
    z.D = point c-3/4 of k1;
    z.E = point c+3/4 of k1;

    vardef tangent expr t of p = 
        (left--right) scaled 42 rotated angle direction t of p shifted point t of p
    enddef;

    draw tangent a of k0 dashed withdots scaled 1/8 withcolor 1/2 red;
    draw tangent b of k0 dashed withdots scaled 1/8 withcolor 1/2 red;
    draw tangent c of k1 dashed withdots scaled 1/8 withcolor 1/2 red;

    draw z.D -- z.C -- z.E dashed evenly withpen pencircle scaled 1/4;

    draw k0 withcolor 2/3 red;
    draw k1 withcolor 2/3 red;

    draw z.R -- origin dashed evenly withpen pencircle scaled 1/4;
    draw z.S -- origin dashed evenly withpen pencircle scaled 1/4;
    label.urt("$R$", z.R);
    
    forsuffixes @ = A, B, C:
        draw (x@, 0) -- z@ -- (0, y@) dashed withdots scaled 1/4;
        label.bot("$\scriptstyle x^" & str @ & "$", (x@, 0));
        label.lft("$\scriptstyle y^" & str @ & "$", (0, y@));
    endfor
    forsuffixes @ = A, B, C, D, E:
        dotlabel.urt("$" & str @ & "$", z@);
    endfor

    drawarrow xx;
    drawarrow yy;

    dotlabel.llft("$0$", origin);
    label.rt("$k^0$", point 8 of k0);
    label.rt("$k^1$", point 8 of k1);
    label.rt("$x$", point 1 of xx);
    label.top("$y$", point 1 of yy);
endfig;
\end{mplibcode}
\end{document}

答案3

使用tzplot

在此处输入图片描述

\documentclass{standalone} 

\usepackage{tzplot}

\begin{document}

\begin{tikzpicture}[scale=1.5,font=\scriptsize]
%\tzhelplines[thick](5,1/0.25)
\tzaxes(5,1/0.25){$x$}{$y$}
\tzshoworigin
% def functions
\def\kzero{1/\x}
\def\kone{2/\x}
\def\lineA{1.8*\x}
\def\lineB{(1/5)*\x}
% indifference curves
\tzfn\kzero[.28:4.4]{$k^0$}[r]
\tzfn\kone[.55:4.4]{$k^1$}[r]
% dashed rays
\tzfn[dashed]\lineA[0:1.5]{$R$}[ar]
\tzfn[dashed]\lineB[0:4]
% intersection points
\tzXpoint*{kzero}{lineA}(A){$A$}[r]
\tzXpoint*{kone}{lineA}(C){$C$}[r]
\tzXpoint*{kzero}{lineB}(B){$B$}[a]
% tangent lines
\tztangent[densely dashed,red]{kzero}(A)[.3:1.1]{$a$}[b]
\tztangent[densely dashed,red]{kone}(C)[.7:1.5]{$c$}[b]
\tztangent[densely dashed,red]{kzero}(B)[1.5:3]
\tztangent[draw=none]{kzero}(A)[1.1:.3]{$a$}[l] % label
\tztangent[draw=none]{kone}(C)[1.5:.7]{$c$}[l]  % label
% projections
\tzproj(A){$x^A$}{$y^A$}
\tzproj(B){$x^B$}{$y^B$}
\tzproj(C){$x^C$}{$y^C$}
% more lines: CD and CE
\tzvXpointat*{kone}{0.7}(D){$D$}[r]
\tzvXpointat*{kone}{1.6}(E){$E$}[ar]
\tzline[densely dashed,blue](C)(D)
\tzline[densely dashed,blue](C)(E)
\end{tikzpicture}

\end{document}

相关内容