Plotting functions in two dimensions

Functions play an important role in mathematics. To visualize them to better understand their properties, so that we can see roots and extreme points, we can plot them in a coordinate system. In this recipe, we will see how to easily plot functions. First, let's print the polynomial function f(x) = x^3 - 5*x.

How to do it...

We will use the pgfplots package, which is based on PGF/TikZ. We already used it in the previous chapter to draw various diagrams. Now it will plot a function for us. Follow these steps:

  1. Start with a document class. For this recipe, we decide on the standalone class, which is great for creating single graphics with just a small margin, but you can choose the article class or another one as ...

Get LaTeX Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.