We can't find the internet
Attempting to reconnect
Something went wrong!
Attempting to reconnect
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.gradorbackward()withrequires_grad=True -
JAX:
jax.grad(f)(x)
Hints
autograd
gradient
torch.autograd
jax.grad
Sign in to attempt this problem and view the solution.