Function Repository Resource:

EnhancedGrad

Source Notebook

Grad enhanced to evaluate using limits and at several points

Contributed by: Dennis M Schneider

ResourceFunction["EnhancedGrad"][f,{x1,,xn},{a1,,an}]

returns the gradient evaluated at the point {a1,,an}.

ResourceFunction["EnhancedGrad"][f,{x1,,xn}]

returns Grad[f,{x1,,xn}].

ResourceFunction["EnhancedGrad"][f,{x1,,xn},chart]

returns the gradient with respect to chart.

Details and Options

The option "UseLimit" computes the gradient at one or more points using Limit. This can help to avoid an indeterminate result.

Examples

Basic Examples (2) 

Find the gradient of a function evaluated at several points:

In[1]:=
ResourceFunction["EnhancedGrad"][
 f[x, y], {x, y}, {{x0, y0}, {x1, y1}}]
Out[1]=

Grad is unable to find the correct value of the gradient of the following function at the point (0,0):

In[2]:=
Grad[(x y)^(2/3), {x, y}] /. ResourceFunction["PointsToRules"][{0, 0}, {x, y}]
Out[2]=

EnhancedGrad is able to find the correct value of the gradient by setting the option "UseLimit" to True:

In[3]:=
ResourceFunction["EnhancedGrad"][(x y)^(2/3), {x, y}, {0, 0}, "UseLimit" -> True]
Out[3]=

A piecewise function requiring "UseLimit":

In[4]:=
Clear[f]
f[x_, y_] := \[Piecewise] {
   {x + (x^2 + y^2)  Sin[1/Sqrt[x^2 + y^2]], {x, y} != {0, 0}},
   {0, {x, y} == {0, 0}}
  }
{ResourceFunction["EnhancedGrad"][f[x, y], {x, y}, {0, 0}],
 ResourceFunction["EnhancedGrad"][f[x, y], {x, y}, {0, 0}, "UseLimit" -> True]}
Out[6]=

Publisher

Dennis M Schneider

Version History

  • 1.0.0 – 11 January 2021

Related Resources

License Information