Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Can someone recommend an online article or introductory tutorial that will show me how to do real and complex line integrals using Mathematica?

share|improve this question
    
Closely related: Symbolic integration in the complex plane –  Jens Feb 17 '13 at 3:08

1 Answer 1

Here's a quick function that does a real line integral:

SyntaxInformation[
   lineIntegrate] = {"LocalVariables" -> {"Plot", {3, 3}}, 
   "ArgumentsPattern" -> {_, _, _}};


lineIntegrate[r_?VectorQ, f_Function, {t_, tMin_, tMax_}] := 
 Module[{param, localR}, localR = r /. t -> param;
  Integrate[(f[localR, #] Sqrt[#.#]) &@D[localR, param], {param, tMin,
     tMax}]]

lineIntegrate[{Cos[t], Sin[t]}, 1 &, {t, 0, 2 Pi}]

(* ==> 2 Pi *)

The second argument is a function to be evaluated at points along the curve. This function in turn can take two arguments: the position $\vec{r}$ and the derivative of the position with respect to the parameter, $d\vec{r}/dt$.

One could modify this definition so the function takes only the curve parameter as the argument, but I settled on this so that I can calculate things like work integrals easily. For example, take a closed path in 3D, and show that the work along it under a conservative force $\vec{F} = (0, 0, z)$ vanishes:

ParametricPlot3D[{Cos[t], Sin[t], Sin[2 t]}, {t, 0, 
  2 Pi}, PlotStyle -> Tube[.01]]

path

work[r_, tangent_] := {0, 0, r[[3]]}.tangent

lineIntegrate[{Cos[t], Sin[t], Sin[2 t]}, 
 work[#1, #2/Sqrt[#2.#2]] &, {t, 0, 2 Pi}]

(* ==> 0 *)
share|improve this answer
    
There's an error in that example: when I evaluate it I'm getting error Function::sloth : Slot number 2 in work[#1,#2/Sqrt[#2.#2]]& cannot be filled from.... –  murray Feb 17 '13 at 18:09
    
@murray Thanks, I edited the definition of the function. I originally had f only as a single argument function and forgot to copy the new definition when I edited the example. –  Jens Feb 17 '13 at 18:18
    
To keep things parallel with Integrate and NIntegrate, it would be a good idea also to have an NlineIntegrate variant. (The change to get that would be the obvious one.) –  murray Feb 17 '13 at 18:33
    
@murray Certainly. Looking at it now, I should also switch the order of the first two arguments for more consistency. But I think I'll wait with further edits until the OP comes back with feedback... it was supposed to be for illustrative purposes. –  Jens Feb 17 '13 at 18:53
    
I'm afraid that the code above is far too advanced for me to understand, so I'm going to have to ask some questions and take some time to learn more Mathematica before I can understand this answer. Let me start with these questions: (1) What is the purpose of SyntaxInformation? (2) What does "LocalVariables" -> {"Plot", {3, 3}} accomplish? (3) I was able to try the ArgumentsPattern and watch what happens if you enter too few or too many arguments to the function, but may I ask what would "Arguments"->{_, __, ___} mean? –  David Feb 18 '13 at 1:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.