vector calculus in mathematica - engineering school class web sites

14
Page | 1 Vector Calculus in Mathematica Craig Beasley Department of Electrical and Systems Engineering Washington University in St. Louis St. Louis, MO March 21, 2012 Vector calculus is a staple of the engineering disciplines. Many of the phenomena we deal with have directions associated with them, and those directions need to be preserved during mathematical operations. The mathematics involved can become tedious and cumbersome, especially in three dimensions. Furthermore, three dimensional problems tend to be difficult to visualize and draw. The ability to perform the proper calculations quickly and accurately combined with a visual model of what’s going on is an enormous boon for problem-solving. Several new concepts will be introduced that are not exclusively related to vectors: Most notably, loading supplemental packages, three-dimensional graphing, and labeling axes. Vector Addition & Subtraction Since a vector is just a matrix with only one row, addition and subtraction with vectors works exactly like it does for matrices. You will not need the MatrixForm command, and because of the way the MatrixForm command interacts with other Mathematica operations, its use should be discouraged. Dot Product The dot product operation can be performed in one of two ways. The first is to refer back to matrix multiplication and use a period. The second is to use the Dot command, and since that follows the same syntax as the TI-89, this guide will use that exclusively.

Upload: others

Post on 12-Sep-2021

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Vector Calculus in Mathematica - Engineering School Class Web Sites

Page | 1

Vector Calculus in Mathematica

Craig Beasley Department of Electrical and Systems Engineering Washington University in St. Louis St. Louis, MO March 21, 2012 Vector calculus is a staple of the engineering disciplines. Many of the phenomena we deal with have directions associated with them, and those directions need to be preserved during mathematical operations. The mathematics involved can become tedious and cumbersome, especially in three dimensions. Furthermore, three dimensional problems tend to be difficult to visualize and draw. The ability to perform the proper calculations quickly and accurately combined with a visual model of what’s going on is an enormous boon for problem-solving. Several new concepts will be introduced that are not exclusively related to vectors: Most notably, loading supplemental packages, three-dimensional graphing, and labeling axes. Vector Addition & Subtraction Since a vector is just a matrix with only one row, addition and subtraction with vectors works exactly like it does for matrices. You will not need the MatrixForm command, and because of the way the MatrixForm command interacts with other Mathematica operations, its use should be discouraged. Dot Product The dot product operation can be performed in one of two ways. The first is to refer back to matrix multiplication and use a period. The second is to use the Dot command, and since that follows the same syntax as the TI-89, this guide will use that exclusively.

Page 2: Vector Calculus in Mathematica - Engineering School Class Web Sites

Page | 2

Cross Product Like its counterpart, the cross product operation has two means of entry. The first is to use the cross operator located on the template. The second is to use the Cross command. This guide will focus on the second, for the reason indicated above.

Below is an example of syntax for how to enter a cross product.

VectorPlot The VectorPlot command will plot a vector field. The proper syntax to produce a generic two-dimensional vector field that uses the default graphical settings is: VectorPlot[vector,{first axis,low,high},{second axis,low,high}]

Page 3: Vector Calculus in Mathematica - Engineering School Class Web Sites

Page | 3

There will be times when you want to change the number of vector arrows displayed on the page, or to alter the size of the vector arrows. This can be done with the VectorPoints and VectorScale parameters. VectorPoints accepts a matrix input, allowing the user to specify how many rows and columns of vector arrows appear. VectorScale accepts a size parameter, either a word or a numeric value. For reference, 0.1 and Small are close to the same size.

Page 4: Vector Calculus in Mathematica - Engineering School Class Web Sites

Page | 4

Vector functions can also be plotted with the VectorPlot command.

VectorPlot3D Attaching 3D to the end of any type of Plot command will generate the appropriate three-dimensional graph. Doing so requires a range be set for an additional axis.

Page 5: Vector Calculus in Mathematica - Engineering School Class Web Sites

Page | 5

Labeling Axes and Rotating Graphs With so much going on inside of the previous graph, it starts to become apparent why there is a need for changing the size and quantity of the vector arrows. Unfortunately, it’s difficult to make sense of that graph because the axes aren’t labeled. It is a standard procedure in an engineering environment to clearly label the axes of a graph or figure so that the reader understands what it is they’re looking at. Computer modeling not only allows us to draw complicated objects, but also to rotate the figure and observe it from multiple angles.

Mathematica allows a three-dimensional graph to be rotated by clicking on the graph and sweeping the mouse in the desired direction of rotation. Two more screenshots will follow. The axes have also been renamed to give you a better feel for how the AxesLabel command works.

Page 6: Vector Calculus in Mathematica - Engineering School Class Web Sites

Page | 6

Page 7: Vector Calculus in Mathematica - Engineering School Class Web Sites

Page | 7

ContourPlot & ContourPlot3D Level curves and surfaces can be plotted in Mathematica. These are the constant-value regions of a particular function. The command behaves very much like the Plot and VectorPlot command. The result of a standard ContourPlot command will show up color-coded. Warm colors are large values and cool colors are small values. By inserting a double equal sign, a specific level curve can be plotted.

Page 8: Vector Calculus in Mathematica - Engineering School Class Web Sites

Page | 8

The hot/cold color coding does not hold for three-dimensional plots. When looking at the general case, it is difficult to tell what is going on, as you will see in the images below

Page 9: Vector Calculus in Mathematica - Engineering School Class Web Sites

Page | 9

ParametricPlot & ParametricPlot3D With the number of Plot commands covered by now, ParametricPlot should require little more than a visual example.

Three dimensional parametric curves are likewise simple and straightforward, only adding a third element in the vector.

Page 10: Vector Calculus in Mathematica - Engineering School Class Web Sites

Page | 10

The ParametricPlot3D command can also be used to plot a parametric surface.

Needs VectorAnalysis In order to utilize some of the vector calculus operations, Mathematica needs to load an extra package. The VectorAnalysis package is loaded thusly:

Note that there is a tilde on the end of VectorAnalysis. Do not forget that, or the package won’t load. The VectorAnalysis package requires special variable definitions. In the forthcoming topics, pay attention to the form of the variables used by each of the commands. If you try to use any other variables besides those loaded with VectorAnalysis, the computer will not understand what you want it to do and your command will fail to execute properly.

Page 11: Vector Calculus in Mathematica - Engineering School Class Web Sites

Page | 11

Since the three following operations are defined differently for Cartesian, cylindrical, and spherical coordinate systems, the VectorAnalysis package loads all three. The default is Cartesian, but this can be changed with the SetCoordinates command.

Gradient Mathematica has a Gradient command embedded natively. This is the wrong command. I can’t stress this heavily enough. Everybody’s favorite upside-down triangle is the Grad command, just the same as it’s abbreviated in calculus textbooks.

Compare that to the following functions in cylindrical and spherical coordinates. Also note that Mathematica can be told inside of the command which coordinate system to use, rather than having to set a new default every time.

Divergence Just like the Grad command, divergence uses the same abbreviation as a standard calculus manual. Do not forget that the input to the divergence command is a vector instead of a scalar.

Page 12: Vector Calculus in Mathematica - Engineering School Class Web Sites

Page | 12

Likewise, do not forget that the divergence operator is defined differently for each coordinate system.

Remember, the coordinate system you are working in matters a lot. If the latter two results look nasty and unfriendly, it’s because the original function didn’t have cylindrical or spherical symmetry. Curl Curl is the most tedious of the three operators to compute by hand. Computation by machine is no more difficult than the previous two.

Page 13: Vector Calculus in Mathematica - Engineering School Class Web Sites

Page | 13

Line Integrals If you can take an integral, you can take a line integral. Some work is required to set up a parametric curve and plug that into a vector function. After that, a line integral is evaluated by taking a dot product and integrating over bounded region. Using Example #2 from page 415 of the textbook, where F = [z,x,y]:

A TI-89 is able to compute line integrals in the same manner. Construction of a Normal Vector A surface integral operates very much like a line integral. The hardest part is finding a normal vector. First, the surface must be parameterized. A normal vector is found by taking partial derivatives and then calculating a cross product. Using Example #1 from page 444-445 of the textbook, where F = [3z^2,6,6xz]:

Page 14: Vector Calculus in Mathematica - Engineering School Class Web Sites

Page | 14

Surface Integrals We are now ready to calculate a surface integral. The process will look much like a line integral. Instead of calculating all of the individual pieces by hand, I am going to plug everything into an integral. The machine itself is capable of doing all of the intermediary steps: partial derivatives, dot products, and cross products. This is something that can also be put into a TI-89. Still using Example #1 from page 444-445 of the textbook, here is what comes out:

Broken down into parts, it looks like this: