All problems
Dual-Number Jacobian
Problem
Forward-mode automatic differentiation evaluates a function on dual numbers (value, derivative).
For f(x, y) = [x*y + x, x^2 - y], seed x first and then y to assemble the Jacobian [[df1/dx, df1/dy], [df2/dx, df2/dy]]. Return the numeric matrix, which equals [[y + 1, x], [2x, -1]].
Hint
Each forward sweep computes one Jacobian column for the cost of one function evaluation.
Test cases
case 1
in: [1,2]
expected: [[3,1],[2,-1]]
case 2
in: [0,0]
expected: [[1,0],[0,-1]]
case 3
in: [2,-1]
expected: [[0,2],[4,-1]]
case 4
in: [-1,3]
expected: [[4,-1],[-2,-1]]
Starter codePython
def dual_jacobian(x, y):
# Return the 2x2 Jacobian
# Your code here
pass4 test cases · run your code against them in the editor