I am having trouble working with xtick
and ytick
functionality within \pgfplotsset
tag which I use for axis manipulation for all my tikzpicture
tags for sketching graphs.
I call this pair many times before the following code, which I am having trouble with.
\documentclass[]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{pgfplots}
\usepackage{mathtools}
\usepackage{cancel}
\usepackage{pgfplots}
\usepackage{amsmath}
\newtheorem{theorem}{THEOREM}
\newtheorem{proof}{PROOF}
\usepackage{tikz}
\usepackage{amssymb}
\usetikzlibrary{patterns}
\usepackage{bigints}
\usepackage{color}
\usepackage{tcolorbox}
\usepgfplotslibrary{fillbetween}
\begin{document}
\textbf{1}\\
\pgfplotsset{every axis/.append style={
axis x line=middle, % put the x axis in the middle
axis y line=middle, % put the y axis in the middle
axis line style={<->}, % arrows on the axis
xlabel={$x$}, % default put x on x-axis
ylabel={$y=\cos 3x$}, % default put y on y-axis
ticks=both,
ytick={-1,0,1},
yticklabels={-1,0,1},
xtick={0,0.523,1.046,1.57},
xticklabels={0,$\frac{\pi}{6}$,$\frac{\pi}{3}$,$\frac{\pi}{2}$}
}}
% arrows as stealth fighters
\tikzset{>=stealth}
\begin{tikzpicture}
\begin{axis}[
xmin=0,xmax=2,
ymin=-2,ymax=2,
domain = 0:1.58
]
\plot[thick][samples=50,domain=0:1.57] {cos(3*deg(x)))};
\addplot[dashed] expression {-1};
\addplot[dashed] expression {1};
\end{axis}
\end{tikzpicture}
\\
\\
\textbf{27}\enskip Since the gradient of the tangent is 1, we
find all possible $x$ values for which $\dfrac{d}{dx}(x+\sin x)=1$ is satisfied.\\
$\dfrac{d}{dx}(x+\sin x)=1$ is equivalent to $1+\cos x=1$ which simplifies to $\cos x=0$. \\
\\
\pgfplotsset{every axis/.append style={
axis x line=middle, % put the x axis in the middle
axis y line=middle, % put the y axis in the middle
axis line style={<->}, % arrows on the axis
xlabel={$x$}, % default put x on x-axis
ylabel={$y=\cos x$}, % default put y on y-axis
ticks=both,
ytick={-1,0,1},
yticklabels={-1,0,1},
xtick={0,1.57,3.14,4.71,6.28,7.85,9.42},
xticklabels={0,$\frac{\pi}{2}$,$\pi$,$\frac{3\pi}{2}$,$2\pi$,$\frac{5\pi}{2}$,$3\pi$}
}}
% arrows as stealth fighters
\tikzset{>=stealth}
\begin{tikzpicture}
\begin{axis}[
xmin=0,xmax=9.6,
ymin=-2,ymax=2
]
\plot[thick][samples=50,domain=0:9.43] {cos(deg(x))};
\addplot[dashed,domain=0:9.43] expression {-1};
\addplot[dashed,domain=0:9.43] expression {1};
\end{axis}
\end{tikzpicture}\\
As shown in the cosine graph above $x$ can take are $\dfrac{\pi}{2}$,$\dfrac{3\pi}{2}$ and $\dfrac{5\pi}{2}$.\\
\\
\textbf{30}\enskip The equation of the tangent to the curve $y=e^{x}$ at the point $(1,e)$ is $y-e=e^{1}(x-1)$ which is $y=ex$.\\
Since this tangent touches the curve $y=2\sqrt{x-k}$ at some point, let this point be $x=\alpha$. We must have
$$\begin{cases}
e\alpha=2\sqrt{\alpha-k} & (1)\\
e=\dfrac{1}{\sqrt{\alpha-k}} & (2)
\end{cases}$$
where (1) and (2) are from the fact that the line $y=ex$ being the tangent to curve $y=2\sqrt{x-k}$ at $x=\alpha$.\\
\\
Solving (1) and (2) simulataneously gives $k=\dfrac{1}{e^2}$.\\
\\
\pgfplotsset{every axis/.append style={
axis x line=middle, % put the x axis in the middle
axis y line=middle, % put the y axis in the middle
axis line style={<->}, % arrows on the axis
xlabel={$x$}, % default put x on x-axis
ylabel={$y$}, % default put y on y-axis
ticks=none
}}
% arrows as stealth fighters
\tikzset{>=stealth}
\begin{center}
\begin{tikzpicture}
\begin{axis}[
xmin=-0.4,xmax=3,
ymin=-1,ymax=5,
domain = 0:3
]
\plot[thick,brown][samples=50,domain=-0.5:1.57] {2.718^x};
\node [right] at (axis cs: 1.6, 4.8) {$y=e^{x}$};
\plot[thick,black][samples=50,domain=0:1.57] {2*sqrt{x-0.1353}};
\node [right] at (axis cs: 1.6, 4) {$y=ex$};
\plot[thick,red][samples=50,domain=-0.5:1.57] {2.718*x)};
\node [right] at (axis cs: 1.6, 2.3) {$y=2\sqrt{x-k}$};
\draw[style=dashed] (axis cs:1,0) -- (axis cs:1,2.71);
\draw[style=dashed] (axis cs:0,2.71) -- (axis cs:1,2.71);
\node [below] at (axis cs: 1,0) {$1$};
\draw[style=dashed] (axis cs:0.2707,0) -- (axis cs:0.2707,0.73575);
\end{axis}
\end{tikzpicture}
\newline
\end{center}
\textbf{3}
The following is the plot of the function $y=\dfrac{1}{x-3}+x$:\\\\
\pgfplotsset{every axis/.append style={
axis x line=middle, % put the x axis in the middle
axis y line=middle, % put the y axis in the middle
axis line style={<->}, % arrows on the axis
xlabel={$x$}, % default put x on x-axis
ylabel={$y$}, % default put y on y-axis
ticks=none
}}
% arrows as stealth fighters
\tikzset{>=stealth}
\begin{tikzpicture}
\begin{axis}[
xmin=-1,xmax=7,
ymin=-10,ymax=20,
]
\plot[thick][samples=100,domain=-1:2.95] {1/(x-3)+x};
\plot[thick][samples=100,domain=3.05:7] {1/(x-3)+x};
\plot[dashed][samples=100,domain=-1:7] {x};
\draw[dashed] (axis cs:3,-10) -- (axis cs:3,20);
\node [below] at (axis cs: 3.2, 0) {$3$};
\draw[black,thick,fill=black] (axis cs: 0.3819,0) circle (0.4mm);
\node [below] at (axis cs: 0.6, 0) {$\frac{3-\sqrt{5}}{2}$};
\draw[black,thick,fill=black] (axis cs: 2.618,0) circle (0.4mm);
\node [below] at (axis cs: 2.2, 0) {$\frac{3+\sqrt{5}}{2}$};
\draw[black,thick,fill=black] (axis cs: 0,-0.333) circle (0.mm);
\node [left] at (axis cs: 0, -2) {$-\frac{1}{3}$};
\node [below] at (axis cs: 3.2, 0) {$3$};
\end{axis}
\end{tikzpicture}\\
We call the asymptote $y=x$ an \textbf{oblique}.\\\\
\\
\textbf{39}\\
\pgfplotsset{every axis/.append style={
axis x line=middle, % put the x axis in the middle
axis y line=middle, % put the y axis in the middle
axis line style={<->}, % arrows on the axis
xlabel={$x$}, % default put x on x-axis
ylabel={$f(x)$}, % default put y on y-axis
ytick={-1,0,1,2,3,4,5},
yticklabels={$-1$,$0$,$1$,$2$,$3$,$4$,$5$},
xtick={-3,-2,-1,0,1,2,3,4,5,6},
xticklabels={$-3$,$-2$,$-1$,$0$,$1$,$2$,$3$,$4$,$5$,$6$}
}}
% arrows as stealth fighters
\tikzset{>=stealth}
\begin{tikzpicture}
\begin{axis}[
xmin=-4,xmax=7,
ymin=-2,ymax=5,
]
\plot[thick][samples=100,domain=-2.5:7] {4-(2)^(-x)};
\draw[dashed] (axis cs:-4,4) -- (axis cs:7,4);
\end{axis}
\end{tikzpicture}
\end{document}
The following is what I get:
However when I call this code on its own I get what I want correctly:
What is suppressing my xtick
and ytick
functions? I have checked that in the previous call for \pgfplotsset
, where necessary I set ticks=\empty
, if this helps.