medium framework

Compute Gradient

Compute the gradient of f(x) = x^3 + 2x^2 + x at a given point using automatic differentiation.

The analytical derivative is f'(x) = 3x^2 + 4x + 1.

Input: A scalar value x.

Output: A scalar tensor equal to f'(x).

API Reference:

  • PyTorch: torch.autograd.grad or backward() with requires_grad=True
  • JAX: jax.grad(f)(x)

Hints

autograd gradient torch.autograd jax.grad
Detecting runtime...