Tuesday, January 10, 2017

Drawing vertical tangents when the gradient is undefined.

A common thing that I want to do in Desmos is draw a tangent line to a function that a user can drag around or animate. A simple way I have been using is below:


Problem

There is a slightly annoying problem with this method: If the derivative is undefined at a point then the graph won't display a vertical tangent; it just won't draw a line at all here.



Solution

I recently found a way to test for undefinedness in Desmos. The expression {k = k: 0, 1} will return 1 if k is undefined (or 0 if it's defined). So we can use this technique to graph a separate vertical line at x = a when the value of f'(a) is undefined.

Note that if the gradient is defined, I actually don't want this line to appear at all, which is why I threw in an undefined value (if I just put 0 here then it would graph x = 0 for these values of a).

I am much happier with this version of the graph.

[Update] Minor Technical Problem: Undefined function values

After posting this, I realised that the additional rule will also graph a vertical line when the function itself is undefined at a point. I'm not sure what the best behaviour is for this case, but perhaps it would be nice to have a draggable point along the x-axis with no vertical line.

To implement this, change line 2 from (a, f(a)) to a more complicated conditional

And the vertical tangent line can be set to only appear when the function is defined but the derivative is undefined.


No comments:

Post a Comment