Loading commands, almost done…
A vector field can be derived from a scalar function by computing its gradient. In this example, we define a scalar function:
The gradient of this function gives us a vector field where each vector points in the direction of steepest ascent. The gradient is:
Let's visualize this vector field and see how changing the parameter a affects it.
First, we define the parameter a:
a = \scalar 1Now we need a point to evaluate the function and its gradient. Let's start with a point p:
p = \point 0 0To compute , we need to extract the x and y coordinates:
px = \x-coord ppy = \y-coord pNow we calculate the squared terms:
px-squared = \mul px pxpy-squared = \mul py pyMultiply a by :
a-px-squared = \mul a px-squaredFinally, compute :
out = \sub a-px-squared py-squaredNow we can visualize the vector field using the \vector-field command, which automatically computes the gradient at each point:
\vector-field p outTry changing the value of a to see how the vector field transforms.
Notice how the vector field changes shape as you modify a. When a is positive, the vectors point outward in the x-direction, and when a is negative, they point inward.