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:
torch.autograd.grad or backward() with requires_grad=True jax.grad(f)(x)