File:Vector Field of a Function's Gradient imposed over a Color Plot of that Function.svg
From Wikimedia Commons
Jump to navigation
Jump to search
Size of this PNG preview of this SVG file: 720 × 360 pixels. Other resolutions: 320 × 160 pixels | 640 × 320 pixels | 1,024 × 512 pixels | 1,280 × 640 pixels | 2,560 × 1,280 pixels.
Original file (SVG file, nominally 720 × 360 pixels, file size: 280 KB)
File information
Structured data
Captions
Summary
[edit]DescriptionVector Field of a Function's Gradient imposed over a Color Plot of that Function.svg |
English: An arrow plot of the gradient of the function , superimposed over a color plot of the values of that function, demonstrating that the gradient yields a vector field of a given function.
The plot was generated using Numpy and Matplotlib in Python 3.11.0 using the following code: import matplotlib.pyplot as plt
import numpy as np
# Returns the partial derivative with respect to the `i`th parameter of the
# given function. This is done using the method of finite differences
def partial_derivative(f, i=0, h=0.001e-10):
def partial(*xs):
dxs = list(xs)
dxs[i] = xs[i] + h
return (f(*dxs)-f(*xs))/h
return partial
# Returns an np.array (a vector) of partial derivatives with respect to each
# parameter given, ie the gradient
def gradient(f):
def gradient_of_f(*xs):
return np.array([partial_derivative(f, i)(*xs) for i in range(len(xs))])
return gradient_of_f
# The function to be plotted. It contains, by construction, an adjacent 'sink' and
# 'source'. These features demonstrate that the gradient operator yields a vector
# field wherein each vector points from sinks (lower values) to sources (higher values)
def f(x, y):
return x * np.exp(-1 * (x**2 + y**2))
# Here we construct our domain (the inputs) by discretizing the space between -2 and 2
# into 25 evenly spaced points. This is done for both the x and y dimensions.
n = 25
x = np.linspace(-2, 2, n)
y = np.linspace(-2, 2, n)
# Then we generate a grid of points from our two dimensions, on which we'll evaluate
# the above function
x, y = np.meshgrid(x, y)
# Then we do said evaluating
z = f(x, y)
# And generate it's gradient. Note that `gradient` returns a single array, for plotting
# convenience I've separated out the the dx and dy parts.
dzdx, dzdy = gradient(f)(x, y)
# And finally we generate the plot
plt.figure(figsize=(8, 4))
plt.pcolormesh(x, y, z)
plt.quiver(x, y, dzdx, dzdy, scale=n, pivot='mid', headwidth=4, minshaft=2, minlength=2)
plt.colorbar()
plt.plot()
|
Date | |
Source | Own work |
Author | Colejhudson |
Licensing
[edit]I, the copyright holder of this work, hereby publish it under the following license:
This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
- You are free:
- to share – to copy, distribute and transmit the work
- to remix – to adapt the work
- Under the following conditions:
- attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
- share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
File history
Click on a date/time to view the file as it appeared at that time.
Date/Time | Thumbnail | Dimensions | User | Comment | |
---|---|---|---|---|---|
current | 19:40, 8 January 2023 | 720 × 360 (280 KB) | Colejhudson (talk | contribs) | Uploaded own work with UploadWizard |
You cannot overwrite this file.
File usage
There are no pages that use this file.
Global file usage
The following other wikis use this file:
Metadata
This file contains additional information, probably added from the digital camera or scanner used to create or digitize it.
If the file has been modified from its original state, some details may not fully reflect the modified file.
Width | 576pt |
---|---|
Height | 288pt |
Structured data
Items portrayed in this file
depicts
Some value without a Wikidata item
8 January 2023
image/svg+xml
Hidden categories: