Skip to content
DeepForgeby svx
All problems
MediumCalculusca-067

Mixed Partial Finite Difference

Problem

Approximate the mixed partial derivative of f(x, y) = x^m * y^n at (x, y) with the four-point central stencil:

f_xy ≈ (f(x+h, y+h) - f(x+h, y-h) - f(x-h, y+h) + f(x-h, y-h)) / (4*h^2)

Use h = 1e-4. The analytic value is m*n*x^(m-1)*y^(n-1).

Hint

The stencil is a symmetric cross difference; divide by 4 h squared.

Test cases

case 1
in: [2,3,1,2]
expected: 24.00000003177638
case 2
in: [1,1,3,4]
expected: 1.00000003833145
case 3
in: [2,2,0,5]
expected: 0
case 4
in: [3,1,2,1]
expected: 12.00000001588819
Starter codePython
def mixed_partial(m, n, x, y, h=1e-4):
    # f(x, y) = x**m * y**n
    # Your code here
    pass

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