Loading commands, almost done…
This example demonstrates how to plot a function and draw a tangent line at a point. We'll work with the function y = x · sin(x) and explore how to visualize both the function and its tangent at any point.
First, let's define our function y = x · sin(x). We'll use the variable x as our input:
x = \scalar 4Now calculate y using the sine function:
sin-x = \sin xy = \mul x sin-xDefine colors:
Hide the origin point p0:
Set animation speed:
To see the full function curve, we can use the plot command directly with our x and y variables:
\plot x yYou could give a name to the plot (eg my-plot = \plot x y). However a name is auto-assigned when not provided. To know the auto-assigned name, just hover the mouse anywhere over the plot. In this case, the auto-assigned name must be plot0.
Let's create a point at (x, 0) on the x-axis and a point at (x, y) on the function:
\line p-x-axis p-funcThe tangent command automatically calculates the derivative and draws the tangent line at the given x coordinate on the plot:
Let's animate x from -4 to 4 to see how the tangent line changes as we move along the function:
One can also use an array of points as input to tangent function.