Partial Derivatives and the Gradient

~12 mincode completion

Implement gradient_at(x, y) returning as a two-element list, using the analytic formulas above.

Examples

At (2, 1) the partials are 4 and 7

Input
gradient_at(2, 1)
Output
[4, 7]

On the y axis the x partial vanishes but the y partial does not

Input
gradient_at(0, 2)
Output
[0, 12]

At the origin the surface is flat to first order

Input
gradient_at(0, 0)
Output
[0, 0]

Hints

Hint 1

Work directly with the arguments x, y and return the result rather than printing it.

Hint 2

Watch for this: treats the frozen variable as if it were zero.

Requirements

  • x: first coordinate

  • y: second coordinate

  • Return list of two floats: [df/dx, df/dy]

Constraints

  • Standard library only, no imports required

  • Time limit: 200 ms, Memory: 64 MB

Where this shows up

~12 min

6 employers weight this skill

4 quant funds, 1 big tech firm, 1 frontier lab. Top match scores 93.

Python
def gradient_at(x, y):
    """
    Analytic gradient of f(x, y) = x^2*y + y^3.

    Args:
        x: first coordinate
        y: second coordinate

    Returns:
        list of two floats: [df/dx, df/dy]
    """
    # YOUR CODE HERE
    pass
Loading docs…

The AI Mentor needs an account

It reads your code and the failing tests and nudges you toward the fix without handing you the answer. Free accounts get it on every problem you're working on today.