number of segments

function

f(x) = sin(x)
n = 15 (slider from 1 to 50, step 1)
A = Corner(1)
B = Corner(3)
delta_x: (x(B) - x(A)) / (n + 1)
list0 = Sequence(x(A) + i * delta_x, i, 1, n)
list2 = Sequence((Element[list0, i], f(Element[list0, i])), i, 1, n)
n_{old} = 15
w = 0.2 (slider from 0 to 0.5, step 0.1)
f'(x) = f'(x)
list1 = Sequence(x = Element[list0, i], i, 1, n)
linewidth: w * delta_x
inputBox1 = Textfield(n)
inputBox2 = Textfield(f)
togPrime = 1
text1 = If(togPrime ≟ 1, "Show derivative.", "Hide derivative.")
A_{1} = Point(Element[list1, 1])
A_{2} = Point(Element[list1, 2])
A_{3} = Point(Element[list1, 3])
A_{4} = Point(Element[list1, 4])
A_{5} = Point(Element[list1, 5])
A_{6} = Point(Element[list1, 6])
A_{7} = Point(Element[list1, 7])
A_{8} = Point(Element[list1, 8])
A_{9} = Point(Element[list1, 9])
A_{10} = Point(Element[list1, 10])
A_{11} = Point(Element[list1, 11])
A_{12} = Point(Element[list1, 12])
A_{13} = Point(Element[list1, 13])
A_{14} = Point(Element[list1, 14])
A_{15} = Point(Element[list1, 15])
a_{1} = Segment(Element[list2, 1] - linewidth * (1, y(A_{1})), Element[list2, 1] + linewidth * (1, y(A_{1})))
a_{2} = Segment(Element[list2, 2] - linewidth * (1, y(A_{2})), Element[list2, 2] + linewidth * (1, y(A_{2})))
a_{3} = Segment(Element[list2, 3] - linewidth * (1, y(A_{3})), Element[list2, 3] + linewidth * (1, y(A_{3})))
a_{4} = Segment(Element[list2, 4] - linewidth * (1, y(A_{4})), Element[list2, 4] + linewidth * (1, y(A_{4})))
a_{5} = Segment(Element[list2, 5] - linewidth * (1, y(A_{5})), Element[list2, 5] + linewidth * (1, y(A_{5})))
a_{6} = Segment(Element[list2, 6] - linewidth * (1, y(A_{6})), Element[list2, 6] + linewidth * (1, y(A_{6})))
a_{7} = Segment(Element[list2, 7] - linewidth * (1, y(A_{7})), Element[list2, 7] + linewidth * (1, y(A_{7})))
a_{8} = Segment(Element[list2, 8] - linewidth * (1, y(A_{8})), Element[list2, 8] + linewidth * (1, y(A_{8})))
a_{9} = Segment(Element[list2, 9] - linewidth * (1, y(A_{9})), Element[list2, 9] + linewidth * (1, y(A_{9})))
a_{10} = Segment(Element[list2, 10] - linewidth * (1, y(A_{10})), Element[list2, 10] + linewidth * (1, y(A_{10})))
a_{11} = Segment(Element[list2, 11] - linewidth * (1, y(A_{11})), Element[list2, 11] + linewidth * (1, y(A_{11})))
a_{12} = Segment(Element[list2, 12] - linewidth * (1, y(A_{12})), Element[list2, 12] + linewidth * (1, y(A_{12})))
a_{13} = Segment(Element[list2, 13] - linewidth * (1, y(A_{13})), Element[list2, 13] + linewidth * (1, y(A_{13})))
a_{14} = Segment(Element[list2, 14] - linewidth * (1, y(A_{14})), Element[list2, 14] + linewidth * (1, y(A_{14})))
a_{15} = Segment(Element[list2, 15] - linewidth * (1, y(A_{15})), Element[list2, 15] + linewidth * (1, y(A_{15})))

Tool: Func-tan-thru-Pt (command FuncTanThruPt)
select function and point
Input: f, F
Output: tangentLines, tangentPoints

f(x) = -2 * x^(3) + 2 * x^(2) - 4 * x + 7
g(x) = (x(F) - x) * f'(x) - (y(F) - f(x))
groots: {Root[g]}
xcoord: x(groots)
ycoord: f(xcoord)
tangentPoints = Sequence((Element[xcoord, j], Element[ycoord, j]), j, 1, Length[xcoord])
tangentLines = Sequence(Line[F, Element[tangentPoints, j]], j, 1, Length[xcoord])