Skip to content
DeepForgeby svx
All problems
EasyCalculusca-012

Tangent Line at a Point

Problem

Return the tangent line to f(x) = sum(coeffs[i] * x^i) at x0 as [slope, intercept].

slope = f'(x0) and intercept = f(x0) - slope * x0, so the line is y = slope * x + intercept.

Hint

Differentiate term by term, then shift the line down by slope * x0 to get the intercept.

Test cases

case 1
in: [[0,0,1],3]
expected: [6,-9]
case 2
in: [[1,2,3],2]
expected: [14,-11]
case 3
in: [[5],1]
expected: [0,5]
case 4
in: [[0,1],0]
expected: [1,0]
Starter codePython
def tangent_line(coeffs, x0):
    # Return [slope, intercept]
    # Your code here
    pass

4 test cases · run your code against them in the editor