如何制作像这样的图形上的切线?

如何制作像这样的图形上的切线?

我是一个 tikz 初学者,希望绘制这个图形:在此处输入图片描述数字

我在这里尝试了一次又一次,但无法进一步...谢谢帮助!

\documentclass{article}

\usepackage{lmodern}
\usepackage[T1]{fontenc}

\usepackage{tikz}
\usetikzlibrary{calc, hobby}
\tikzset{
        tangent/.style = {
            in angle={(180+#1)},
            Hobby finish,
            designated Hobby path=next,
            out angle=#1
        }
    }

\begin{document}
    \begin{figure}[htbp]
        \centering
        \begin{tikzpicture}

        \coordinate (y) at (0,5);
        \coordinate (x) at (6,0);

        \coordinate (sp0) at (2.75,0);
        \coordinate (ep0) at (4.75,3);
        \coordinate (csp0) at (3.5,2);
        \coordinate (cep0) at (3.75,-0.5);

        \coordinate (sp1) at (ep0);
        \coordinate (ep1) at (5.5,4);
        \coordinate (csp1) at (5.25,5);
        \coordinate (cep1) at (5.25,2);

        \coordinate (sp2) at (sp0);
        \coordinate (ep2) at (-0.25,-0.65);
        \coordinate (csp2) at (1.5,0);
        \coordinate (cep2) at (1.5,0);

        \draw[<->] (y) node[left] {$y$} -- (0,0) --  (x) node[below] {$x$};

        % Using \pgfmathanglebetweenpoints to calculate the angle for tangent
        % tangent takes a degree unit angle
        \pgfmathanglebetweenpoints{\pgfpointanchor{cep0}{center}}{\pgfpointanchor{ep0}{center}}
        \let\angle=\pgfmathresult
        \draw (ep2) to [curve through ={(sp0) .. ([tangent=\angle]ep0)}] (ep1) ;

        \draw[dashed] (cep0) -- (csp1);
        \draw[dotted] let \p1 = (ep0) in (ep0) -- (0,\y1);
        \draw[dotted] let \p1 = (ep0) in (ep0)-- (\x1,0);

        \draw let \p1 = (ep0) in (\x1,1pt) -- (\x1,-3pt) node[anchor=north] {$x_0$};
        \draw let \p1 = (cep0) in (\x1,1pt) -- (\x1,-3pt) node[anchor=north] {$x_1$};
        \draw let \p1 = (ep0) in (1pt,\y1) -- (-3pt,\y1) node [anchor=east] {$f(x_0)$};
        \end{tikzpicture}
        \caption{Newtons metode}
        \label{fig:newtonsmetode}
    \end{figure}
\end{document}

答案1

John Kormylo 已经提到,如果使用显式函数,则只需计算其切线的斜率即可。

\documentclass{article}
\usepackage{lmodern}
\usepackage[T1]{fontenc}

\usepackage{tikz}
\usetikzlibrary{calc,intersections}

\begin{document}
\begin{figure}[htbp]
 \centering
 \begin{tikzpicture}[>=stealth,
    declare function={f(\x)=-0.35+5*exp(\x/2)/exp(3);
        fprime(\x)=2.5*exp(\x/2)/exp(3);},
    dot/.style={circle,fill,inner sep=1pt},
    every pin edge/.style={thin}]
  \path (0,0) coordinate[label=below left:{$O$}] (O)
     (0,5) coordinate (y) (6,0) coordinate (x);
  \draw[->,name path=x-axis] (-0.5,0) --  (x) node[below] {$x$};
  \draw[->] (0,-0.5) --  (y) node[left] {$y$};
  \draw[semithick,cyan,name path=curve] plot[variable=\x,domain=0.1:6,smooth]
   (\x,{f(\x)}) (5.8,{f(6)})node[black,left]{$y=f(x)$};
  \draw[red,dashed] (5.5,0) coordinate(x0) -- (5.5,{f(5.5)}) coordinate(p0)
  ($(p0)+(-1,{-1*fprime(5.5)})$) coordinate(p0');
  \draw[red,dashed] (intersection of p0--p0' and O--x) coordinate (x1)
  let \p1=(x1) in \pgfextra{\pgfmathsetmacro{\myx}{\x1/1cm}}
  (x1) -- (\myx,{f(\myx)}) coordinate(p1)
  ($(p1)+(-1,{-1*fprime(\myx)})$) coordinate(p1');
  \draw[red,dashed] (intersection of p1--p1' and O--x) coordinate (x2)
  let \p1=(x2) in \pgfextra{\pgfmathsetmacro{\myx}{\x1/1cm}}
  (x2) -- (\myx,{f(\myx)}) coordinate(p2)
  ($(p2)+(-1,{-1*fprime(\myx)})$) coordinate(p2');
  \path (intersection of p2--p2' and O--x) coordinate (x3)
    (x3) node[draw,label=below:{$x_{3}$}] {}
  foreach \X [count=\Y] in {0,...,2}
   {(x\X) node[draw,label=below:{$x_{\X}$}] {}
    (x\Y) edge[red,shorten >=-1em,shorten <=-1ex] (p\X)
   \ifnum\X=0   
   (p\X) node[dot,cyan,label={[black]left:{$(x_{\X},f(x_{\X}))$}}] {}
   \else
   (p\X) node[dot,cyan,pin={[black]90:{$(x_{\X},f(x_{\X}))$}}] {}
   \fi 
   };
  \path[name intersections={of=curve and x-axis,by=i}]
   (i) node[cyan,draw,fill,
   ,pin={[black,align=center]90:point\\ sought}](in){};  
 \end{tikzpicture}
 \caption{Newtons metode}
 \label{fig:newtonsmetode}
\end{figure}
\end{document}

在此处输入图片描述

相关内容