# A guide to MD

## Purpose

The purpose with MD is to illustrate the basic content of a Multi Dimensional Calculus course. It can also be used as a computational tool.

## What you can do

1. Create a (plane) curve c and compute corresponding curve integrals of a given function u.
2. Create a (plane) parameter domain of definition D for functions u and v.
3. Plot given functions u and v.
4. View the divergence and rotation of a given field (u,v).
5. View the Laplacian of u.
6. Integrate given functions over D.
7. View the tangent plane of a given function u.
8. View level curves and/or the gradient field of a given function.
9. Visualize a given vector field (u,v).
10. View the corresponding domain map.
11. Plot the Jacobian of the map.
12. Compute the work integral of a given field along a curve.
13. Compute the flow of a given vector field across a curve.
14. Verify the basic integral theorems of Multi Dimensional Calculus.

## How to do it

1. Start MD by moving to the directory ~kenneth/matlab (or copy the files MD.m, MD.mat and R2adm.m to your matlab directory), start matlab, and type MD at the matlab prompt.
2. To define a curve you press the "curve" button. You can then enter a curve by defining "x=" and "y=" as functions of a parameter s which runs from 0 to 1, and then press "ok". You can also enter a (closed piecewise linear) curve by mouse clicking counter clockwise at selected points in the lower plot area, for example to define the boundary of a two dimensional parameter domain D.
3. To compute curve integrals you press the buttons "u ds", "work" and "cross flow".
4. To proceed to define a parameter domain D, you press "domain" after having defined a closed counter clockwise curve c.
5. To view the mesh underlying plotting and integration you may want to press "mesh'.
6. To plot a desired function you define "u=" or "v=" and press return.
7. To integrate the function you press "integrate".
8. To plot the divergence or rotation of the field (u,v), or the Laplacian of u, you press the corresponding buttons.
9. To view the gradient field and/or level curves of function u, you check the corresponding boxes.
10. To view the (u,v) field as an arrow plot in the (x,y) domain you press "uv field".
11. To view (u,v) as a change of coordinates and view the corresponding (u,v) domain, or the corresponding Jacobian, you press the button signed "uv map" or "jacobian". The color of the (u,v) domain indicates a positive and/or negative Jacobian.
12. To verify the integral theorems of Multi Dimensional Calculus, you may compute the divergence and the corresponding integral over D and compare it to the cross flow integral of the (u,v) field, and similarly compute the rotation of (u,v) and the corresponding integral and compare it to the work integral. It is also instructive to compare all these integrals to the corresponding "uv field" plot.
13. Finally, you may view the tangent plane approximation of a given function u, by pressing the "tangent plane" button and then a selected point in the parameter domain D.
14. To obtain a finer mesh for plotting and/or integration to may want to press "refine".
15. You may also modify a given curve and/or domain by pressing "modify", and then click and drag selected points on the curve c to another position. You may also have to redefine the computational domain by pressing "domain", and re-evaluate the functions u and v, or whatever quantity you are studying.
14. If somethings goes wrong, so that the program doesn't cooperate, it may be best to type "close" at the matlab prompt, and make a restart.

## Example tours

### A curve integral

We compute the length of the spiral r=v, 0<v<10, by pressing "curve" and typing "x=" 10*s*cos(10*s) and "y=" 10*s*sin(10*s), pressing "ok" and then "u ds".

### A double integral

We plot and compute the integral of exp(y*sin(x)) on the unit square by pressing "curve", clicking one at a time at the points (0,0), (1,0), (1,1), (0,1) and (0,0) in the parameter domain plot area, then press "domain" to define the domain interior to the given curve, and finally type "u=" exp(y.*sin(x)), (Note the .*!) followed by a return to plot u, and then press "integrate". You may also enter the curve vertices by declaring c global at the matlab prompt by >>global c, and then defining c by >>c=[0 0;1 0;1 1;0 1;0 0], and then press the "domain" button.

### Viewing level curves and/or gradient field

With domain and function u as above we may check and/or un check the "contour" and "gradient" boxes to see the level curves and/or gradient field of u.

### Viewing vector fields

For example, press the "u=" button and then choose from the uv menu the function sin(12*x.*y) to define u this way, and then press the "v=" button and choose from the uv menu the function x.^2+y.^2 to have v defined this way (if you are too lazy to type in these formulas directly), and then press the "uv field" button.

### Change of coordinates

To consider a more familiar example, redefine "u=" and "v=" as x.*cos(y) and x.*sin(y), respectively. Press "jacobian" to plot the jacobian, and "uv map" to see the corresponding domain in the new coordinates u and v. Check that this conforms with what you expected to happen!

### div, rot, Laplace

Define u=x.^k and v=y.^k with k=1,2 and view the corresponding div (u,v) plots. Also view the corresponding "uv field plots. Also plot the corresponding rot (u,v).
Repeat with u=-y.^k and v=x.^k.
View the Laplacian or div(grad) of u with u=4*x-7*y, u=x.^2, u=x.^2+v.^2, and u=log(x.^2+y.^2), for example.

### Gauss theorem

The theorem states that the total outflow through the boundary B of a domain D of a "flow field" (u,v), that is the integral over the boundary curve B of the (outward) normal component of (u,v), is equal to the total "well production" of D, that is the integral over D of the local "well production" div (u,v). Consider for example the field u=x, v=y. Plot the flow field by pressing "uv field". Is there a net outflow or inflow through the boundary of your domain? What is the well production in different parts of your domain? Press "div(u,v)" to view the local production. The compare the integral over D of div(u,v) with that of the integral over B of the total outflow. Conclusions? You may want to refine the computational mesh by pressing "refine" and recompute the divergence and the integrals.

### Stokes theorem (in 2D)

The theorem states that the circulation along the boundary B of a domain D of a vector field (u,v) is equal to the total "curl" or rotation of the vector field inside B, that is in D. In other words, the integral along B of the tangential component of (u,v) is equal to the integral over D of dv/dx-du/dy. Consider for example the field u=-y and v=x. Plot the field with "uv field". Compute and plot the local rotation of the field by pressing "rot(u,v)". Compare the integral of rot(u,v) over D with the "work" (or circulation) integral of (u,v) along B.

## Problems

1. Find the work applied by of the force field (-y,x) to move a particle along the spiral curve r=v from v=0 to v=10.
2. Find the volume of Scandinavium with radius 10 and height 5+(x/10)^2-(y/10)^2.
3. Find the center of gravity of the domain enclosed by the curve x=abs(2*pi*s-pi)*sin(2*pi*s), y=-abs(2*pi*s-pi)*cos(2*pi*s), 0<s<1. Hint: Only the y-coordinate of the center is non-trivial. Can be found by computing the integrals of y and 1, respectively, over D. Note that the function 1 must be entered as ones(size(x)) or ones(size(y)).
4. Find the total mass of the triangular plate with vertices in (0,0), (1,0) and (0,1) with surface density x/(1+y). (Don't spend too much time getting the exact positions of the vertices!) Compare to problem 51.12.3 in EM2000.
5. Find the total charge of the domain with vertices (0,0), (1,0), (2,1) and (2,2) with charge density x+y. Compare to problem 51.4.3!
6. Find the approximate maxima/minima of the function exp(-x.^2-y.^2).*(x+2*y). Hint1: Study the level curves/gradient field! Hint2: To extend the parameter domain, point close to the boundary you would like to move.
7. Compare the integrals along three different curves from (0,0) to (1,1) of the fields (u,v)=(x,y)=grad(x^2/2+y^2/2), (u,v)=(y,x)=grad(xy), and (-y,x), respectively. Conclusions?
8. ... To be continued!!!