I've searched MMA SE and read all of the posts on surface integrals, and several people have helped on various pieces of code to evaluate them.
I seem to have found a simple and correct code from users here.
For example, in the following problem:
region = ImplicitRegion[x^2 + y^2 + z^2 == 1 && x^2 - x + y^2 <= 0 && z >= 0, {x, y, z}];
Integrate[#, {x, y, z} \[Element] region] & /@ ({x^2, y^2, z^2}.{x, y,z})
This code works because the very last part of this code, the curly bracketed {x,y,z} is the normal vector of the sphere. So, knowing that, you can just enter it.
But I'm interested in making this code more generalizable by having code that will determine the normal vector of any surface and then, in that last line, just automatically refer back to that calculation. Any sense of how I could do that?
Thanks in advance for your patience and help.
UPDATE:
Thanks for the code below. Very helpful. Sometimes MMA seems to have trouble calculating the integral, or it takes a long time. But often the question I'm asked is to just set up the integral. So following the example of @cvgmt's code, I have the following step by step, but I'm not sure how to complete it.
x[u_, v_] := 2 u v;
y[u_, v_] := u^2 - v^2;
z[u_, v_] := u^2 + v^2; r := {x[u, v], y[u, v], z[u, v]};
(*The following code takes cross product of the partial derivatives
of r and calculates magnitude*)
a = Cross[D[r, u], D[r, v]];
b = Norm[a];
c = FullSimplify[b] (*This simplifies the normal*)
(*Enter the parametrized integrand as f*)
f := (2 u v)^2 + (u^2 - v^2)^2
(*Fully simplify the dot product of the normal and the surface
integrand, which will give you the final integrand for calculation*)
FullSimplify[f.c]
One thing here that is confusing is that this result gives me a couple "Abs(u)" or "Abs(v)" in it. I don't know how to get rid of those and it keeps the equation from fully simplifying.
Normalize
andGrad
. $\endgroup$Integrate[ vfield.unorm, {x, y, z} \[Element] region]
$\endgroup$Norm[a,Sqrt[#.#]&]
instead ofNorm[a]
as in my code. Or simplely useSqrt[a.a]
SinceAbs
is a complex function,It need to useComplexExpand
to simplify. $\endgroup$