I was writing out a document, and tried to insert the image of a graph. However, the image gets displayed before the text it is placed after. How do I rectify this?
\section{Problem 3}
Find the number of roots of the equation $x+2\tan x=\frac{\pi}{2}$ in the interval $\left[0,2\pi\right]$.
\subsection{Solution}
Rewrite the equation to get
\begin{equation*}
\tan x=\frac{\pi}{4}-\frac{x}{2}
\end{equation*}
Now let us graph two functions, namely $y=\tan x$ and $y=\frac{\pi}{4}-\frac{x}{2}$ in the interval $\left[0,2\pi\right]$. Their common intersection points give us the exact number of solutions.
\begin{figure}
\centering
\includegraphics[width=0.5\linewidth]{desmos-graph(3).png}
\end{figure}
As we can clearly see, $y=\frac{\pi}{4}-\frac{x}{2}$ is a line with negative slope, and it \textit{will} intersect the graph of $\tan x$. As shown, there will be $\boxed{3}$ solutions.
\includegraphics[width=0.5\linewidth]{desmos-graph(3).png} is the line in which the image is included. However, when I compile my pdf, this is the outcome

How do I correct this?
figureenvironment to allow it to move,\includegraphicswould include the image at the point specified – David Carlisle Nov 04 '23 at 14:13\begin{figure}and it works perfectly fine – Doge with shades Nov 04 '23 at 14:21