concept potential energy function in category python

This is an excerpt from Manning's book Math for Programmers: 3D graphics, machine learning, and simulations with Python.
With a potential energy function, we’ll use several Matplotlib visualizations to see what it looks like. One important example is called a heatmap, which uses darker and brighter colors to show how the value of a scalar field changes over a 2D space (figure 11.4).
The basic idea is as follows: instead of picturing gravity as a force vector at every point, pulling objects toward a source, we can think of objects in a gravitational field like marbles rolling around in a bowl. The marbles may roll back and forth, but they are always “pulled” back toward the bottom of the bowl as they roll away. A potential energy function essentially defines the shape of this bowl. You can see a preview of what the bowl looks like in the center image of figure 11.16.
We’ll write potential energy as a function, taking a point (x, y) and returning a single number, representing the gravitational potential energy at the point (x, y). In terms of the bowl analogy, this is something like the height of the bowl at a given point. Once we implement a potential energy function in Python, we can visualize it in three ways: as a heatmap, which you saw at the beginning of this chapter, as a 3D graph, and as a contour map as shown in figure 11.16.
Figure 11.16: Three pictures of a scalar field: a heatmap, a graph, and a contour map
![]()
These visualizations will help us picture potential energy functions in the final section of this chapter and in the remaining chapters of the book.