<jupyter_start><jupyter_text>Multivariable Calculus - Gradient of a Scalar Field*ENGSCI 211 Mathematical Modelling 2*  Background to NotebookThis notebook contains two demos aimed at improving your understanding of the gradient of a scalar field and the directional derivative. gradient()This demo contains two subplots.The subplot on the left shows the 3D surface associated with a function of two independent variables. The red points are the stationary points of the surface, and the black point is the one used in the gradient ascent/descent algorithm used in the other subplot.The subplot on the right shows, by default, a 2D contour plot of the surface. The red points indicate stationary points i.e. local minimum, maximum or saddle points for the surface. The black point is the starting location for an iterative gradient ascent/descent algorithm and can be modified. To see how the gradient vector points in direction of fastest increase in the function, you can increase the *iteration number* slider and change the step size to see how moving along the local gradient vector (gradient ascent), or negative gradient vector (gradient descent) can move towards a local stationary point. You can optionally show the entire gradient vector field of the surface. directionalderivative()This demo contains two subplots.The subplot on the left shows the 3D surface associated with a function of two independent variables. The red points are the stationary points of the surface, and the black point is the one used in the directional derivative calculation.The subplot on the right shows, by default, a 2D contour plot of the surface. The red points indicate stationary points i.e. local minimum, maximum or saddle points for the surface. The black point is the point at which the directional derivative is calculated. The gradient vector, $\nabla f$, at that point is shown as a blue vector. The direction, $\hat{a}$, in which we wish to determine the function's rate of change (i.e. the directional derivative) is shown as a red **unit** vector and can be modified. The dot product, $\nabla f \cdot \hat{a}$, along the direction of $\hat{a}$ is shown as a green vector and the value of $\nabla f \cdot \hat{a}$ is equal to the rate of change of $f$ along the direction $\hat{a}$ at the chosen point i.e. the directional derivative.  Notebook ExamplesThere are three different examples included in this notebook. The position vector for each example is given by:$$f_4 \, (x,y) = \frac{x^3}{3} - \frac{y^3}{3} - x + y + 3$$$$f_5 \, (x,y) = x^2 - y^2$$<jupyter_code># run this cell prior to the others
from sourcecode_mc import gradient, directionalderivative
%matplotlib inline
gradient()
directionalderivative()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.05680990531682447, 'fraction_numerical': 0.006190823015294974, 'mean_word_length': 4.807610993657505, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '226726', 'license': 'MIT', 'n_tokens_mistral': 688, 'n_tokens_neox': 644, 'n_words': 414, 'path': 'engsci211_mc2_gradient.ipynb', 'repo_name': 'csim456/notebooks211', 'size': '2746'}