Description

The gradient of a function $g(x, y)$ is defined as

(1)
\begin{align} \nabla g(x, y) = \left( \frac{\partial g}{\partial x}, \frac{\partial g}{\partial y} \right). \end{align}

The sage cell below calculates the gradient of the function $g(x,y)=xy + \sin(x^2)+e^{-x}$.

Sage Cell

Code

x,y=var('x', 'y')
g(x,y)=x*y + sin(x^2) + e^(-x)
g.gradient()


Options

Option

You can also use g.derivative() or diff(g) to calculate the gradient.

Code

x,y = var('x', 'y')
g(x,y) = x*y + sin(x^2) + e^(-x)
g.derivative()


Tags

Primary Tags: Calculus - multivariable

Secondary Tags: Differentiation of multivariable functions: Directional derivatives and the gradient, Vector calculus: Derivatives