The Chain Rule
~12 mincode completion
Implement chain_rule_derivative(a, b, x) for
y=(ax+b)2
returning dy/dx at x, computed as outer times inner rather than by expanding the square first. The answer is .
Examples
(3x + 1)^2 at x = 2: inner is 7, outer derivative 14, times 3
- Input
- chain_rule_derivative(3, 1, 2)
- Output
- 42
At the point where the inner function is zero the whole derivative vanishes
- Input
- chain_rule_derivative(2, -4, 2)
- Output
- 0
A negative inner slope flips the sign
- Input
- chain_rule_derivative(-1, 5, 1)
- Output
- -8
Hints
Hint 1
Work directly with the arguments a, b, x and return the result rather than printing it.
Hint 2
Watch for this: forgets to multiply by the inner derivative.
Requirements
a: inner slopeb: inner offsetx: the point to differentiate atReturn float: 2(ax + b) * a
Constraints
Standard library only, no imports required
Time limit: 200 ms, Memory: 64 MB
Try similar problems(4)
Where this shows up
~12 min
••••••••
4 employers weight this skill
4 quant funds. Top match scores 93.
Python
def chain_rule_derivative(a, b, x):
"""
dy/dx for y = (a*x + b)^2, via the chain rule.
Args:
a: inner slope
b: inner offset
x: the point to differentiate at
Returns:
float: 2*(a*x + b) * a
"""
# YOUR CODE HERE
pass