2

What is the code to represent a logarithm to the base 10? I would like to graph

y = log_{10}(3x + 1)

on the interval [-0.1, 6].

I would also like to graph the tangent line to the graph at (3, 1). The equation is

y = [3/(10 * ln(10))](x - 3) + 1.

\documentclass[10pt]{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\setlength{\oddsidemargin}{0.0in}
\setlength{\evensidemargin}{0.0in} \setlength{\textwidth}{6.1in}
\setlength{\topmargin}{0.0in} \setlength{\textheight}{9in}

%http://pgfplots.sourceforge.net/pgfplots.pdf

\begin{document}

\noindent \hspace*{\fill}
\begin{tikzpicture}
\begin{axis}[width=6in,axis equal image,clip=false,
    axis lines=middle,
    xmin=-10,xmax=10,
    domain=-10:10, samples=201,
    xlabel=$x$,ylabel=$y$,
    ymin=-2.5,ymax=2.5,
    restrict y to domain=-2.5:2.5,
    enlargelimits={abs=1cm},
    axis line style={latex-latex},
    ticklabel style={font=\tiny,fill=white},
    xtick={\empty},ytick={\empty},
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]
\addplot[samples=501,domain=-0.1:6,blue] {log(3x + 1)} node[above,pos=0.9]{$\scriptstyle{y} = f(x)$};
\draw [fill] (3,1) circle [radius=1.5pt];
\end{axis}
\end{tikzpicture}
\hspace{\fill}
\vskip0.2in


\end{document}
2
  • 1
    The function for the logarithm to base 10 is log10. Note that you need specify multiplication specifically, so you have to say 3*x, not just 3x.
    – Jake
    Oct 14, 2014 at 13:15
  • @Jake Yes, I did find that mistake. I guess that if I wanted to plot the logarithmic function to the base 2, I would code log3(x).
    – Adelyn
    Oct 14, 2014 at 16:13

2 Answers 2

3
\documentclass[10pt]{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\setlength{\oddsidemargin}{0.0in}
\setlength{\evensidemargin}{0.0in} \setlength{\textwidth}{6.1in}
\setlength{\topmargin}{0.0in} \setlength{\textheight}{9in}

%http://pgfplots.sourceforge.net/pgfplots.pdf

\begin{document}

\noindent \hspace*{\fill}
\begin{tikzpicture}
\begin{axis}[width=6in,axis equal image,clip=false,
    axis lines=middle,
    xmin=-10,xmax=10,
    domain=-10:10, samples=201,
    xlabel=$x$,ylabel=$y$,
    ymin=-2.5,ymax=2.5,
    restrict y to domain=-2.5:2.5,
    enlargelimits={abs=1cm},
    axis line style={latex-latex},
    ticklabel style={font=\tiny,fill=white},
    xtick={\empty},ytick={\empty},
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]
\addplot[samples=501,domain=-0.1:6,blue] {log10(3*x + 1)} node[above,pos=0.9]{$\scriptstyle{y} = f(x)$};
\addplot[samples=3,domain=-0.1:6,red] {(x-3)*3/(10*ln(10))+1};
\draw [fill] (3,1) circle [radius=1.5pt];
\end{axis}
\end{tikzpicture}
\hspace{\fill}
\vskip0.2in


\end{document}

enter image description here

For the sake of mathematics: alternatively, using

enter image description here

you get the same thing by:

\documentclass[10pt]{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\setlength{\oddsidemargin}{0.0in}
\setlength{\evensidemargin}{0.0in} \setlength{\textwidth}{6.1in}
\setlength{\topmargin}{0.0in} \setlength{\textheight}{9in}

%http://pgfplots.sourceforge.net/pgfplots.pdf

\begin{document}

\noindent \hspace*{\fill}
\begin{tikzpicture}
\begin{axis}[width=6in,axis equal image,clip=false,
    axis lines=middle,
    xmin=-10,xmax=10,
    domain=-10:10, samples=201,
    xlabel=$x$,ylabel=$y$,
    ymin=-2.5,ymax=2.5,
    restrict y to domain=-2.5:2.5,
    enlargelimits={abs=1cm},
    axis line style={latex-latex},
    ticklabel style={font=\tiny,fill=white},
    xtick={\empty},ytick={\empty},
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]
\addplot[samples=501,domain=-0.1:6,blue] {ln(3*x + 1)/ln(10)} node[above,pos=0.9]{$\scriptstyle{y} = f(x)$};
\addplot[samples=3,domain=-0.1:6,red] {(x-3)*3/(10*ln(10))+1};
\draw [fill] (3,1) circle [radius=1.5pt];
\end{axis}
\end{tikzpicture}
\hspace{\fill}
\vskip0.2in


\end{document}
5
  • 2
    Instead of ln(x)/ln(10), you can simply use log10(x).
    – Jake
    Oct 14, 2014 at 13:21
  • 1
    @Jake Just could'nt resist to add a nice formula ... :-) Oct 14, 2014 at 13:24
  • @Jake As you can see from my code, I did use ln(x)/ln(10) for the logarithmic function to the base 10. I looked in the manual for the code for plotting logarithmic functions. I did not find log10(x) for plotting the logarithmic function to the base 10. Thanks.
    – Adelyn
    Oct 14, 2014 at 16:11
  • 1
    @Adelyn: I'm not sure I understand your comment. A list of the mathematical functions defined in the PGF math engine (which is the engine used in PGFPlots) can be found in the PGF manual, currently on page 935. Three logarithmic functions are defined: ln, log10, and log2.
    – Jake
    Oct 14, 2014 at 16:16
  • 2
    @Jake Yep. Three logarithmic functions are defined in PGFPlots; the others have to be defined in terms of one of these three functions using the Change-of-Base Formula. I looked in the manual for any mention of "log." This word is mentioned hundreds of times, and the first hundred times is in the context of the axes. It was too frustrating to keep looking in the manual. My computer is slow, too. It needs about 15 seconds to load each page. I stopped when I was on page 150 - or something like that.
    – Adelyn
    Oct 14, 2014 at 16:23
0

Here is the code for a nice graph, with the vertical asymptote.

\documentclass[10pt]{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}


\begin{document}

\noindent \hspace*{\fill}
\begin{tikzpicture}
\begin{axis}[width=6in,axis equal image,clip=false,
    axis lines=middle,
    xmin=-3,xmax=10,
    domain=-10:10, samples=501,
    xlabel=$x$,ylabel=$y$,
    ymin=-5,ymax=3,
    restrict y to domain=-5:3,
    enlargelimits={abs=0.5cm},
    axis line style={latex-latex},
    ticklabel style={font=\tiny,fill=white},
    xtick={\empty},ytick={\empty},
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]
\addplot[samples=251,latex-latex,domain=-2.5:10, thin] {(3/(10 * ln(10))) * x - 9/(10 * ln(10)) + 1};
\addplot[samples=501,domain=-0.333:9,blue] {(1/ln(10)) * ln(3*x + 1)}
node[pos=0.9, anchor=north, font=\footnotesize] {$y=\log(3x + 1)$};
\addplot [dashed, latex-latex, samples=251,domain=-5:3] (-1/3,x) node[pos=0.1, anchor=south, font=\footnotesize, sloped] {$x=-\frac{1}{3}$};
\draw [fill] (3,1) circle [radius=1.5pt];
\end{axis}
\end{tikzpicture}
\hspace{\fill}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .