Tikz 图不够精确

Tikz 图不够精确

在下图中,两条曲线应该在 (4,3) 处相交,但实际上并没有。有什么方法可以解决这个问题吗?我尝试加载定点算术库,希望提高精度,但结果仍然相同。还尝试了samples=600,这大大减慢了编译速度,但没有改变输出。我使用的是 tikz,而不是 pgfplots。 曲线应在 (4,3) 处相交 我删除了大量代码以使其“最小化”,但 MWE 仍然很大:

 \documentclass[serif,dvipsnames,table, hyperref={pdfborder={0 0 0}, citecolor=green!50!black, urlcolor=blue,linkcolor=orange, colorlinks=true, bookmarksopen=true}]{beamer}
 \usepackage{tikz}
 \usetikzlibrary{fixedpointarithmetic,external,matrix, automata,trees,positioning,shadows,arrows,shapes.geometric,shapes.multipart,trees,calc, fit, decorations.pathmorphing,decorations.pathreplacing}
 \usepackage{fontspec}
 \usepackage{emerald}
 \usepackage[T1]{fontenc}
 \begin{frame}{\hspace{6cm}General Equilibrium}
 \begin{tikzpicture}[remember picture, overlay,
                                            declare function = { ua(\x,\y)=sqrt(\x)+sqrt(\y);
                                                 ub(\x,\y)=10*sqrt(\x)+8*sqrt(\y);
                                                 ca(\x,\u)=(max(0,\u-sqrt(\x)))^2;
                                                 cb(\x,\u)=((\u-8*sqrt(\x))/10)^2; }]
 \coordinate (C) at ($(current page.center)-(4.5cm,3.2cm)$);

 \begin{scope}[shift=(C)]
 \draw[->,thick] (-.5,0)--++(9.5,0);
 \draw[->,thick] (0,-.5)--++(0,7.5);
 \draw[->,thick] (8.5,6)--++(-9.5,0);
 \draw[->,thick] (8,6.5)--++(0,-7.5);
 \node at (0,7.2) [above] {$c_1^A$};
 \node at (9.5,0) [right] {$c_0^A$};
 \node at (8,-1) [below] {$c_1^B$};
 \node at (-1,6) [left] {$c_0^B$};
 \node at (0,0) [below left]{$0$};
 \node at (8,6) [above right]{$0$};
 \draw[densely dashed](4,0) --++(0,3);
 \draw[densely dashed](0,3) --++(4,0);
 \draw[densely dashed](4,6) --++(0,-3);
 \draw[densely dashed](8,3) --++(-4,0);
 \begin{pgfonlayer}{foreground}
 \filldraw (4,3) circle (1pt);
 \end{pgfonlayer}
 \draw<2,4-7>[decoration={brace, amplitude=3mm, aspect=0.5},thick, red, decorate,rotate=180](-4,0)--(0,0) node[below, yshift=-5mm,xshift=16mm]{\ECFAugie{A's endowment of }$\euler{c_0}$};
 \draw<3>[decoration={brace, amplitude=3mm, aspect=0.5},thick, red, decorate,rotate=180](-8,0)--(-4,0) node[below, yshift=-5mm]{\ECFAugie{B's endowment of }${\euler c_0}$};
 \draw<4-7>[decoration={brace, amplitude=3mm, aspect=0.5},thick, red, decorate,](4,6)--(8,6) node[above, yshift=5mm,xshift=-15mm]{\ECFAugie{B's endowment of }${\euler c_0}$};
 \draw<5-7>[decoration={brace, amplitude=3mm, aspect=0.5},thick, red, decorate](0,0)--(0,3) node[left, yshift=-14mm,xshift=-4mm, text width=1cm]{\ECFAugie{A's  endowment of }${\euler c_1}$};
 \draw<5-7>[decoration={brace, amplitude=3mm, aspect=0.5},thick, red, decorate](8,6)--(8,3) node[right, xshift=6mm,yshift=15mm,text width=1cm]{\ECFAugie{B's  endowment of }$\euler{c_1}$};

 \foreach \r/\s/\d/\e in {2/2/0.1/7,4/3/1/8.5,5/5/3/8.5}{
 \draw<6-10,12> [orange,ultra thick] plot [samples=100, domain=\d:\e]%
 (\x,{ca(\x,ua(\r,\s))}); }

 \foreach  \r/\s/\d/\e in {4/3/1/7}{
 \draw<7-8,10-12> [green!70!black,ultra thick] plot [samples=100, domain=\d:\e] 
                                                                                                    (8-\x,{6-cb(8-\x,ub(\r,\s))});}
 \end{scope}
 \end{tikzpicture}
 \end{frame}
 \end{document}

答案1

如果相关函数在 处相交,(4,3)那么问题似乎在于函数的定义不正确,或者传递给它的和的ub值不正确。\r\s

如果函数不正确,ub则应将其定义为8*sqrt(\x)+10*sqrt(\y)10*sqrt(\x)+8*sqrt(\y)

否则,ub应使用反转的参数来调用该函数:ub(\s,\r)不是ub(\r,\s),或者赋予\r和 的值\s应该是34(不是43)。

更改函数定义如下所示,其中红线表示ub1与原始(绿色)函数相比更正后的函数ub

\documentclass[tikz,border=5]{standalone}

\begin{document}
\begin{tikzpicture}[declare function={%
  ua(\x,\y)=sqrt(\x)+sqrt(\y);
  ub(\x,\y)=10*sqrt(\x)+8*sqrt(\y);
  ub1(\x,\y)=8*sqrt(\x)+10*sqrt(\y);
  ca(\x,\u)=(max(0,\u-sqrt(\x)))^2;
  cb(\x,\u)=((\u-8*sqrt(\x))/10)^2; 
}]

\draw [help lines, opacity=0.5] grid (8,6);
\draw[->,thick] (-.5,0)--++(9.5,0);
\draw[->,thick] (0,-.5)--++(0,7.5);
\draw[->,thick] (8.5,6)--++(-9.5,0);
\draw[->,thick] (8,6.5)--++(0,-7.5);

\draw[densely dashed] (4,0)  |- (0,3) 
  node [at start, below] {4} node [at end, left] {3};
\draw[densely dashed](4,6) --++(0,-3);
\draw[densely dashed](8,3) --++(-4,0);

\foreach \r/\s/\d/\e in {4/3/1/8.5}{
  \draw[orange,ultra thick] plot [samples=100, domain=\d:\e]%
    (\x,{ca(\x,ua(\r,\s))}); }

\foreach  \r/\s/\d/\e in {4/3/1/7}{
  \draw [green!70!black,ultra thick] plot [samples=100, domain=\d:\e]
    (8-\x,{6-cb(8-\x,ub(\r,\s))});}

\foreach  \r/\s/\d/\e in {4/3/1/7}{
  \draw [red!70!black,ultra thick] plot [samples=100, domain=\d:\e]
    (8-\x,{6-cb(8-\x,ub1(\r,\s))});}

\filldraw (4,3) circle (1pt);

\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容