(* Advanced Calculus Package Dennis M. Snow Dept. Mathematics Notre Dame October 1991 Fixed Jacobian, J[], for three variables, January 1996 Removed Cross[], since it is now built in, January 1997 *) BeginPackage["Calculus`Advanced`"] (* Declarations *) Global`Vars::usage = "Vars is a list of variables used by default in calculating Advanced Calculus functions. Initially Vars = {x,y,z}." Norm::usage = "Norm[v] gives the norm (or length) of a vector v." Pr::usage = "Pr[v, w] gives the projection of a vector v onto a vector w." (* Cross::usage = "Cross[v, w] gives the cross product of the 3-dimensional vectors v and w." *) Grad::usage = "Grad[f, v] gives the gradient of f. The optional argument v is a list of the independent variables." CriticalPoints::usage = "CriticalPoints[f, v] finds the critical points of f. The optional argument v is a list of the independent variables." Discriminant::usage = "Discriminant [f,v] gives the discriminant of a function f. The optional argument v is a list of the independent variables." Lagrange::usage = "Lagrange[f, g==c, v] finds the critical points of f subject to the constraint g == c. The optional argument v is a list of the independent variables." Curl::usage = "Curl[F, v] gives the curl of the 3-dimensional vector function F. The optional argument v is a list of the independent variables." Div::usage = "Div[F, v] gives the divergence of the vector function F. The optional argument v is a list of the independent variables." Vector::usage = "Vector[{x0,y0,z0},{x1,y1,z1}] creates a thick line segment from {x0,y0,z0} to {x1,y1,z1} as a Graphics3D object." VectorField::usage = "VectorField[F, {x, x0, x1}, {y, y0, y1}] plots the 2-dimensional vector field F on a grid of points {x,y} where x0 <= x <= x1 and y0 <= y <= y1. VectorField[F, {x, x0, x1, dx}, {y, y0, y1, dy}] will space the grid points {dx,dy} apart. Options are passed to Show[]." J::usage = "J[f,g,{u,v}] gives the Jacobian determinant of the coordinate transformation x = f(u,v), y = g(u,v). J[f,g,h,{u,v,w}] gives the Jacobian determinant of the coordinate transformation x = f(u,v,w), y = g(u,v,w), z = h(u,v,w)." LineIntegrate::usage = "LineIntegrate[f, r, {t, a, b}, v] computes the line integral of the function f along the curve parameterized by the vector function r from t = a to t = b. The optional argument v is a list of the independent variables." FlowIntegrate::usage = "FlowIntegrate[F, r, {t, a, b}, v] computes the flow integral of the vector field F along the curve parameterized by the vector function r from t = a to t = b. The optional argument v is a list of the independent variables." (* Definitions *) Begin["`Private`"] Clear[Global`x,Global`y,Global`z] Global`Vars = {Global`x,Global`y,Global`z} Norm[v_?VectorQ] := Sqrt[v.v] Pr[v_?VectorQ,w_?VectorQ] := (v.w) / (w.w) w (* Cross[v_?VectorQ, w_?VectorQ] := {v[[2]]w[[3]]-v[[3]]w[[2]],v[[3]]w[[1]]-v[[1]]w[[3]], v[[1]]w[[2]]-v[[2]]w[[1]]} *) Grad[f_, v_?VectorQ] := D[f,#]&/@v Grad[f_] := Grad[f,Global`Vars] Discriminant[f_,{x_, y_}] := Simplify[D[f,x,x] D[f,y,y] - D[f,x,y]^2] Discriminant[f_] := Discriminant[f,{Global`Vars[[1]],Global`Vars[[2]]}] CriticalPoints[f_,v_?VectorQ]:= Solve[Grad[f,v] == 0] CriticalPoints[f_] := CriticalPoints[f,Global`Vars] Lagrange[f_,g_==c_?NumberQ,v_?VectorQ] := Module[{lambda},Solve[Eliminate[{Grad[f,v]==lambda Grad[g,v],g == c}, lambda]]] Lagrange[f_,g_==c_?NumberQ] := Lagrange[f,g==c,Global`Vars] Curl[F_?VectorQ,{x_,y_,z_}] := {D[F[[3]],y] - D[F[[2]],z], D[F[[1]],z] - D[F[[3]],x], D[F[[2]],x] - D[F[[1]],y]} Curl[F_?VectorQ] := Curl[F,Global`Vars] Div[F_?VectorQ,v_?VectorQ] := Sum[D[F[[i]],v[[i]]], {i,Length[v]}] Div[F_?VectorQ] := Div[F,Global`Vars] Vector[a_List, b_List] := Graphics3D[{Thickness[0.01], Line[{a,b}]}] VectorField[F_?VectorQ, {x_, x0_, x1_, dx___}, {y_, y0_, y1_, dy___}, Opts___]:= Show[Graphics[{PointSize[0.015], Table[{Point[{x,y}], Line[{{x,y},{x,y}+ F}]}, {x, x0, x1, dx}, {y, y0, y1, dy}]} ], Axes->Automatic, AspectRatio-> Automatic, Opts] J[x_,y_,{u_,v_}] := Det[{{D[x,u], D[x,v]}, {D[y,u], D[y,v]}}] J[x_,y_,z_,{u_,v_,w_}] := Det[{{D[x,u], D[x,v], D[x,w]}, {D[y,u], D[y,v], D[y,w]},{D[z,u], D[z,v], D[z,w]}}] LineIntegrate[ f_, r_?VectorQ, {t_, a_, b_}, v_ ] := Integrate[(f/.Inner[Rule,Take[v,Length[r]],r,List])*Norm[D[r,t]], {t,a,b} ] LineIntegrate[ f_, r_, {t_, a_, b_} ] := LineIntegrate[f,r,{t,a,b},Global`Vars] FlowIntegrate[ F_, r_?VectorQ, {t_, a_, b_}, v_ ] := Integrate[(F/.Inner[Rule,Take[v,Length[r]],r,List]).D[r,t], {t,a,b} ] /; Length[F] == Length[r] FlowIntegrate[ F_, r_?VectorQ, {t_, a_, b_}] := FlowIntegrate[ F, r, {t, a, b},Global`Vars] End[] EndPackage[]