我已經嘗試了一遍又一遍,但仍然無法使它看起來像這樣,特別是切線:
微量元素:(歸功於吉門斯)
\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
函數。也能找到重點C與intersections
圖書館,但我們必須找到X中該點的值XYZ坐標系(除非您使用旋轉坐標系,否則這不會那麼難)。
還有第二種解決方案,在平方根之前加一個減號,但我並沒有真正檢查解決方案是否確實有效。我假設A> 0。乙> 0,即該因子大於 1。k¹ 始終位於以下位置的上方和右側k⁰。
切線由這兩個函數的導數決定(另一個數學解)。在 PGF/TikZ 內部執行此操作並不容易,尤其是在涉及C。
這X價值A,乙和C是他們自己的 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}