# Right code for solving Stoke's Theorem problem

In solving Stoke's Theorem problems, I have developed a step by step method. I'm now trying to write a MMA script to help me solve these problems. But I'm a little stuck.

Here's my step by step method, which works well if tediously by hand.

So imagine this problem:

Using Stoke's Theorem, solve the surface integral $$F(x,y,z) = Cos(z)i + x^2j + 2yk$$ where $$C$$ is the intersection of the plane $$z = 2-x$$ and $$x^2 + y^2 = 4$$. The answer is 8$$pi$$.

I started my step by step with this code, but bogged down in how to make each vector element from the curl into the $$P, Q, R$$ of Step 2 and how then to multiply the partial derivatives by $$P,Q,R$$ in Step 5.

F = {Cos[z],  x^2, 2 y}
C = Curl[F, {x, y, z}] (*Step 1*)

g = 2 - x (*Step 3 solving for z of the curve*)
g1 = D[g, x] )(*Step 4*)
g2 = D[g, y]


Thanks for any help.

UPDATE:

Daniel was kind enough to supply some code, which looks great. But I'm trying to reconcile answers from books with how this code solves problems. So his code gives -8pi to a problem where the book says 8 pi. That could be an orientation issue. But here's an example from a UPenn math class (see 1example 1 where Daniel's code says the answer is -4pi, but the professor says "pi." Here's the code I used to evaluate Example 1. Perhaps I misunderstood the application.

f[x_, y_, z_] = {y^2 z, x z, x^2 y^2};
curl[x_, y_] = Curl[f, {x, y, z}];
surf[x_, y_] = {x, y, x^2 + y^2};
surfelem[x_, y_] =
Cross[D[surf[x0, y], x0], D[surf[x, y0], y0]] /. {x0 -> x,
y0 -> y};
reg = ImplicitRegion[x^2 + y^2 == 1, {x, y}];
Integrate[curl[x, y].surfelem[x, y], {x, y} \[Element] reg]

• Step 2 is seemingly trivial, no? You clearly recognize how to write F in the {Pi, Qj, Rk} format, so it should be no issue to recognize that the output of C is in this format. Then you have a trivial application of this recognition for step 5. The issue I see is how you can find g (I myself would want to see this done within the code, such that I know the method is solid & usable for other cases). – CA Trevillian Dec 29 '20 at 4:42
• Yes, trivial, I agree. But I wanted my step by step to be idiot-proof, for me, the idiot. It was easy for me to get confused that the P,Q,R used here is not that of the original field, but is the curl. This makes it different than the use of P,Q, R in other types of problems. So just keeps it clear for me. – JDVC Dec 29 '20 at 4:46
• If you can provide some insight as to how you found your expression for g(x, y) in step 3, I can likely give some suitable answer. – CA Trevillian Dec 29 '20 at 4:52
• Since I set z = g(x,y), and the problem says z = 2-x, I have g(x,y) = 2-x. Then partials of dx = -1 and dy = 0. – JDVC Dec 29 '20 at 4:55
• There is really an error: Instead of Curl[f, {x, y, z}] it should read Curl[f[x,y,z], {x, y, z}] . Then you get 8Pi. However, the integral is independent of how you parametrize the surface. Parametrizing using a region is much more general than an explicite parametrizing. An explicit parametrizing is often hard or impossible to find. – Daniel Huber Dec 30 '20 at 9:26

We first define the vector field and the curl (note, use lower case symbols, as uppercase are used by MMA):

f[x_,y_,z_] = {Cos[z], x^2, 2 y};
curl[x_, y_] = Curl[f[x,y,z], {x, y, z}];


Then we define the surface and the surface element, that we get by the cross product between the derivative of the surface in x and y direction:

surf[x_, y_] = {x, y, 2 - x};
surfelem[x_, y_] =
Cross[D[surf[x0, y], x0], D[surf[x, y0], y0]] /. {x0 -> x, y0 -> y};


The we need the region over which to integrate:

reg = ImplicitRegion[x^2 + y^2 == 4, {x, y}];


And now the integral is the dot product of the curl and the surface element integrated over the region:

Integrate[curl[x, y].surfelem[x, y], {x, y} \[Element] reg]

• Thanks so much for this excellent answer. A question for you, if you don't mind. You define the plane in your surf[x_,y_] and then the cylinder in your Implicit region. Sometimes the problems have trickier regions. Is it possible to 1) enter your surfaces separately; 2) calculate the curve of intersection; 3) then find the normal, and then 4) Integrate? In your code, you seem (?) to separate the two surfaces into two parts of your code - the "surf[x y] and then the "ImplicitRegion"? – JDVC Dec 29 '20 at 18:29
• In general, you define a region in R2 (2 dimensional) as the parameter region and define a function f: R2 -> R3, that defines the surface, over it. Of course, you may define the region in different ways, depending on your problem. If you define the surface differently, you must still be able to calculate the normal and the area element and do the integral. – Daniel Huber Dec 29 '20 at 19:20
• Thanks so much. A quick, last question. Your code says the answer is -8pi. But the book says 8pi. Thoughts? Is there an issue with orientation? – JDVC Dec 29 '20 at 20:59
• I am sorry for the late comment on this thread. However, I am also in need. Could you possibly aid me in the evaluation of something like f[x_, y_, z_] = {Cos[z], x^2, 2 y}, where x^2+y^2+z^2=9 and z>=0? – Jackie Carson Jan 12 at 1:55

# Reply the updated of the question.

We use the parametric form of the surface z=x^2 +y^2,that is

f[r_, θ_] := {r*Cos[θ], r*Sin[θ], r^2}


Assume the vector field is F[x_, y_, z_] := {y^2*z, x*z, x^2*y^2}; and then we substitute it into the Curl[F[x, y, z], {x, y, z}]

(Curl[F[x, y, z], {x, y, z}] /. Thread[{x, y, z} -> f[r, θ]])


All the code as below.

Clear[F,f];
F[x_, y_, z_] := {y^2*z, x*z, x^2*y^2};
f[r_, θ_] := {r*Cos[θ], r*Sin[θ], r^2};
Integrate[(Curl[F[x, y, z], {x, y, z}] /.
Thread[{x, y, z} -> f[r, θ]]) .
Cross[D[f[r, θ], r], D[f[r, θ], θ]], {r, 0,
1}, {θ, 0, 2 π}]


π

# Reply the original of the question.

Use the same method,we can also calculate the original question.

The parametric surface of z=2-x, 0<= x^2+y^2<=4is

f[r_, θ_] := {2 r*Cos[θ], 2 r*Sin[θ], 2 - 2 r*Cos[θ]};

Clear[F, f];
F[x_, y_, z_] := {Cos[z], x^2, 2 y};
f[r_, θ_] := {2 r*Cos[θ], 2 r*Sin[θ], 2 - 2 r*Cos[θ]};
Integrate[(Curl[F[x, y, z], {x, y, z}] /.
Thread[{x, y, z} -> f[r, θ]]) .
Cross[D[f[r, θ], r], D[f[r, θ], θ]], {r, 0, 1}, {θ, 0, 2 π}]


8 π

# Use x,y as parametric

Clear[f, F];
F[x_, y_, z_] := {y^2*z, x*z, x^2*y^2};
f[x_, y_] := {x, y, z} /. z -> x^2 + y^2;
Integrate[(Curl[F[x, y, z], {x, y, z}] /. {z -> x^2 + y^2}) .
Cross[D[f[x, y], x], D[f[x, y], y]], {x, y} ∈
Disk[{0, 0}, 1]]


π

Clear[F, f];
F[x_, y_, z_] := {Cos[z], x^2, 2 y};
f[x_, y_] := {x, y, z} /. z -> 2 - x;
Integrate[(Curl[F[x, y, z], {x, y, z}] /. z -> 2 - x) .
Cross[D[f[x, y], x], D[f[x, y], y]], {x, y} ∈
Disk[{0, 0}, 2]]


8 π

• Thanks so very much. – JDVC Dec 30 '20 at 2:29