enter image description here

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


Some PSTricks solutions only for fun purposes!

enter image description here

    \pstGeonode[PosAngle=90](*1 {\f}){P}(*3.5 {\f}){Q}
    \pcline[linecolor=blue](Q)(!NQx NPy)\naput{$f(x+\varepsilon)-f(x)$}
    \uput[0](*5 {\f}){\textcolor{red}{$y=f(x)$}}

enter image description here



        (*1.6 {\f(x)}){A}
        (*{1.6 \r\space add} {\f(x)}){B}
  • 2
    Very very nice answer. – Sebastiano May 24 at 19:26

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.)

\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)});
 \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$};

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

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.

%Set unit

%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);

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

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

\documentclass[svgnames, x11names, border = 5pt]{standalone}%
\def\F{x^3-6*x^2 + 9*x + 1}


\psset{unit=2cm, arrowinset=0.12, algebraic, plotstyle=curve, plotpoints=200, dimen=inner}
\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)}$}


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.