3

enter image description here

What packages can I use and what code to draw these functions?

12

Some PSTricks solutions only for fun purposes!

enter image description here

\documentclass[pstricks,border=12pt,12pt]{standalone}
\usepackage{pst-plot,pst-eucl}
\def\f{(x-1)^2/5+1}
\def\L#1#2#3{\psCoordinates[linestyle=dashed](#1)\uput[-90](#1|0,0){$#2\mathstrut$}\uput[180](0,0|#1){$#3$}}
\begin{document}
\begin{pspicture}[algebraic,saveNodeCoors,NodeCoorPrefix=N](-2,-1)(7,5)
    \psaxes[labels=none,ticks=none]{->}(0,0)(-1,-1)(6.5,4.5)[$x$,0][$y$,90]
    \psplot[linecolor=red]{-1}{5}{\f}
    \pstGeonode[PosAngle=90](*1 {\f}){P}(*3.5 {\f}){Q}
    \psdot(Q|P)
    \pcline[nodesep=-2](P)(Q)
    \L{P}{x}{f(x)}
    \L{Q}{x+\varepsilon}{f(x+\varepsilon)}
    \pcline[linecolor=blue](P)(Q|P)\nbput{$\varepsilon$}
    \pcline[linecolor=blue](Q)(!NQx NPy)\naput{$f(x+\varepsilon)-f(x)$}
    \uput[-45]([nodesep=-1]{p}Q){secant}
    \uput[0](*5 {\f}){\textcolor{red}{$y=f(x)$}}
\end{pspicture}
\end{document}

enter image description here

\documentclass[pstricks,border=12pt,12pt]{standalone}
\usepackage{pstricks-add,pst-eucl}


\def\f(#1){((#1+3)/3+sin(#1+3))}
\def\fp(#1){Derive(1,\f(#1))}
\psset{unit=2}

\begin{document}
\multido{\r=2.0+-.1}{19}{%
\begin{pspicture}[algebraic](-1.6,-.6)(4.4,3.4)
    \psaxes[ticks=none,labels=none]{->}(0,0)(-1.6,-.6)(4.1,3.1)[$x$,0][$y$,90]
    \psplot[linecolor=red,linewidth=2pt]{-1}{3.9}{\f(x)}
    %
    \psplotTangent[linecolor=blue]{1.6}{1}{\f(x)}
    \psplotTangent[linecolor=cyan,Derive={-1/\fp(x)}]{1.6}{.5}{\f(x)}
    %
    \pstGeonode[PosAngle={135,90}]
        (*1.6 {\f(x)}){A}
        (*{1.6 \r\space add} {\f(x)}){B}
    \pstGeonode[PosAngle={-120,-60},PointName={x_1,x_2},PointNameSep=8pt]
        (A|0,0){x1}
        (B|0,0){x2}
    \pstGeonode[PosAngle={210,150},PointName={f(x_1),f(x_2)},PointNameSep=20pt]
        (0,0|A){fx1}
        (0,0|B){fx2}
    \pcline[nodesep=-.5,linecolor=green](A)(B)
    %
    \psset{linestyle=dashed}
    \psCoordinates(A)
    \psCoordinates(B)
    %
    \psset{linecolor=gray,linestyle=dashed,labelsep=4pt,arrows=|*-|*,offset=-16pt}
    \pcline(x1)(x2)
    \nbput{$x_2-x_1$}
    \pcline(fx2)(fx1)
    \nbput{$f(x_2)-f(x_1)$}
\end{pspicture}}
\end{document}
  • 2
    Very very nice answer. – Sebastiano May 24 at 19:26
9

I recommend TikZ for that. (I used to love pstricks, and the pstricks solution is really neat and I upvoted it, but having seen what TikZ can do I can no longer recommend pstricks, sorry.)

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}[declare function={f(\x)=0.3*(\x-3.5)^3-\x+7;a=1;b=6;c=4.94;}]
 \draw[-stealth] (-0.5,0) -- (6.5,0);
 \draw[-stealth] (0,-0.5) -- (0,6.5);
 \draw[blue] plot[smooth,domain=0.5:6.1] ({\x},{f(\x)});
 \foreach \X in {a,b}
 {\draw[dashed] (\X,0) node[below]{$\X$} |- (0,{f(\X)}) node[left] {$f(\X)$};}
 \draw ({a},{f(a)}) -- ({b},{f(b)});
 \draw[dashed] (c,0) -- (c,{f(c)});
 \draw[dashed,name path=hori] (a,{f(a)}) -- (b,{f(a)});
 \pgfmathsetmacro{\slopeangle}{atan2(f(b)-f(a),b-a)}
 \draw[red,name path=sloped] (c,{f(c)})  +(\slopeangle:2) -- ++ (\slopeangle+180:4);
 \draw ({a},{f(a)}) + (1,0) arc(0:\slopeangle:1) node[midway,right]{$\beta$};
 \draw[name intersections={of=hori and sloped,by=i}] (i) +(1,0)
 arc(0:\slopeangle:1) node[midway,right]{$\beta$};
\end{tikzpicture}
\end{document}

enter image description here

  • 1
    I have agree with your comment :-). – Sebastiano May 24 at 19:25
  • @Sebastiano hello and I agree with it, too. :) – manooooh May 24 at 20:51
5

Adding a MetaPost solution, for completeness. This is how we did it in a text we write for students. Since I prefer not to put too many labels in the figures, I rather explain in text that the "dashed lines are parallell, and hence ..."

As it is written, one can run context on the file, but one can easily adopt it to be plain MetaPost.

\startMPpage
%Set unit
u=1cm;

%Introduce paths
path p,xax,yax;

% Draw axes
xax = ((-0.5,0)--(7.5,0));
yax = ((0,-0.5)--(0,4));
drawarrow xax scaled u;
drawarrow yax scaled u;

%Define your path p
z0 = (1.5u,u);
z1 = (3u,3u);
z2 = (5u,3u);
z3 = (6.5u,2u);

p = z0{dir 80}..z1..{dir 0}z2..{dir -10}z3;

%Find the right "time" and tangent point (calculated by MetaPost)
t = directiontime (z3-z0) of p;
z4 = point t of p;

%Draw path, secant and tangent
draw p;
draw z0--z3 dashed evenly;
draw (z0--z3) shifted (z4-0.5[z0,z3]) dashed evenly;

label.bot(textext("$(a,f(a))$"), z0);
label.lrt(textext("$(b,f(b))$"), z3);
label.ulft(textext("$(\xi,f(\xi))$"), z4);
\stopMPpage

The result looks like this:

image with resulting curve, secant and tangent

  • You don't need textext in label. Simply using string also works in ConTeXt – Aditya May 27 at 11:31
  • Thanks! Ever since this thread I've always been using textext. In fact, in a continued conversation off-list, Hans wrote "in context just use textext which is better". But that was probably compared to btex and etex. – mickep May 27 at 11:49
3

Some more fun with pstricks, which has a \psPlotTangent command:

\documentclass[svgnames, x11names, border = 5pt]{standalone}%
\usepackage[utf8]{inputenc}
\usepackage{amsmath} 
 \usepackage{auto-pst-pdf}%
\usepackage{pstricks-add}%,
\def\F{x^3-6*x^2 + 9*x + 1}

\begin{document}

\psset{unit=2cm, arrowinset=0.12, algebraic, plotstyle=curve, plotpoints=200, dimen=inner}
\everypsbox{\footnotesize}
\begin{pspicture*}(-1,-1)(6,5.5)
\psaxes[linecolor = LightSteelBlue, ticks=none, labels=none]{->}(0,0)(-2,-1.2)(5,5.5)[$x$,-135][$y$,-135]
 \psplot[linecolor = IndianRed, linewidth =1.2pt]{0.05}{4}{\F}
\psset{linestyle=dashed, linewidth=0.3pt}
\psCoordinates(*0.5 {\F})\uput[d](0.5,0){$a$}\uput[l](0,4.125){$f(a)$)}
\psCoordinates(*3.5 {\F})\uput[d](3.5,0){$b$}\uput[l](0,1.875){$f(b)$)}
\psline[linecolor=Gold, linewidth=0.6pt] (0.5, 4.125)(3.5,1.875)
\psline(1.134,0)(1.134, 4.949)(3.134, 4.949)\uput[d](1.134,0){$c$}
\psline(2.866, 0)(2.866, 1.051)(4.866,1.051)\uput[d](2.866,0){$c_1$}
\psset{linestyle=solid, labelsep=24pt}
\foreach \x in {1.134, 2.866}{\psplotTangent[algebraic, linewidth=0.6pt, Derive={3*x^2-12*x + 9}, linecolor=Gold, showpoints]{\x}{1.5}{\F}}
\psarc(3.5, 1.875){0.4}{143}{180}\uput[161](3.5, 1.875){$\beta$}
\psarcn(1.134, 4.949){0.4}{0}{-37}\uput[-18](1.134, 4.949){$\beta$}
\psarcn(2.866, 1.051){0.4}{0}{-37}\uput[-18](2.866, 1.051){$\beta$}
\rput(5,1.5){$\boxed{\tan\beta = \dfrac{f(b)-f(a)}{b-a} = f'(c)}$}
\end{pspicture*}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.