-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
[Discussion] Representing Vector Integrals #19320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I plan to make the following subclasses.
These classes will inherit from the ping @Upabjojr @divyanshu132 class LineIntegral(Integral):
"""
A class to represent line integral of scalar or vector field
over a curve.
"""
def eval(field, curve):
"""
parameters
field: A scalar or vector field
curve: A curve in space
""" |
A possible workflow can be >>> from sympy import *
>>> from sympy.vector import *
>>> C = CoordSys3D('C')
>>>
>>> t = Symbol('t")
>>>
>>> vectorField = C.x**2*C.i + C.y**3 *C.j + C.k
>>> scalarField = C.x**2*C.y*C.z
>>>
>>> reg = ParamRegion((t), (t, t**2, 0), (-1, 1)) ##Denotes the Curve y = x**2
>>> LineIntegral(vectorField, reg)
Result
>>>
>>> center = C.i + 2*C.j + C.k
>>> r = 2
>>> cir = Circle(center, r, "xy")
>>> LineIntegral(vectorField, cir)
Result
>>>
>>> disc = Disc(center, r, "yz")
>>> SurfaceIntegral(scalarField, disc)
Result |
Let's think of all possible ways to represent integration:
|
We can look at other CAS to get inspiration.
Regions can also be defined by combining equalities and inequalities.
P.S Examples taken from Maple and Mathematica |
@Upabjojr Can you explain what this integral will represent? Will it represent a set of antiderivative of elements of the set. |
Sometimes, the integrals should be defined like |
I would still recommend separate classes (Mathematica uses |
Yes, the |
Some problems on vector integrals: Suppose, if we try to solve problem 2 of the line integral from the link. It is about finding the integral over C where C is the portion of lineIntegral(f(x), Eq(x**2 /4 + y**2 / 9, 1), x > 0, y < 0) Example 4: C is given by lineIntegral(f(x), r=t**3*R.i + (1 − 3t)*R.j + e**t*R.k)
# r can be a default keyword argument which denotes the postion vector
# of general point on curve. Example 5: C is defined as the upper half of the circle centered at the origin of radius 1 with counterclockwise rotation and the portion of y=x2−1 from x=−1 to x=1. |
@friyaz Solving those integrals is generally a very difficult problem. Nevertheless, we can still create classes to represent these integrals. If the algorithm is unable to solve the integral, |
I would suggest using ImplicitConditionIntegral(f(x), Eq(x**2 /4 + y**2 / 9, 1) & (x > 0) & (y < 0)) or, equivalently, ImplicitConditionIntegral(f(x), And(Eq(x**2 /4 + y**2 / 9, 1), x > 0, y < 0)) |
The class for the I have suggested |
Or better yet: start reasoning by how the formula looks like. Do not consider what it's for at first. Let's start by designing the API and finding an intuitive and easy-to-use user interface. After that we can go on writing an algorithm for dealing with what these integrals actually do (e.g. start separating them into line/surface/volume integrals). SymPy users should be able to write the integrals in a very simple way. SymPy should be able to distinguish what these integrals are. |
Yes, I am also in favor of making separate classes.
Thanks for looking at this @Upabjojr. I will try looking at more problems and design a simpler API. Should we still make classes for special objects like sphere or triangles? I think we should as in some cases giving implicit equation can be difficult for users. Consider the surface integral where S is the portion of
|
There is already a module in SymPy about geometric objects, though I have never used it. Maybe let's ignore geometric objects for now... this issue is already too complex. |
@Upabjojr I realized that It is not always possible to distinguish between integrals just by looking at the conditional expression. How can we distinguish between:
ImplicitConditionIntegral(f(x, y, z), Eq(x**2 + y**2, 1) & (x > 0) & (y < 0))
ImplicitIntegral(f(x, y, z), Eq(x**2 + y**2 + z**2, 1)) Maybe we should include a parameter that will help to differentiate. ImplicitIntegral(f(x, y, z), Eq(x**2 + y**2 + z**2, 1), Volume=True) # for a solid sphere |
Most problems on volume integral are of the form where the equation of surfaces bounding the volume is given. Handling them could be complex.
ImplicitIntegral(f(x,y,z), And(Eq(4 - x*y, z), (x, 0, 2), (y, 0, 1))) This can denote the volume bounded by the x-y plane and the surface. Although, there can be a better representation.
This is a more difficult problem to solve. ImplicitIntegral(f(x, y,z), And(Eq(y, 10 - 2*z), Eq(z - 2*x, 0), Eq(z - 5, 0), Eq(x, 0))) For Volume Integrals, And operation can represent Bounded by. |
The other question I have is about is about handling the orientation. |
Yes, we should have a keyword argument that allows users to define the orientation. We do not need to know about the normal vector for scalar fields. The result does not depend on it. |
For surfaces, we are not closed, most problems specify the normal using coordinate axis.
ImplicitIntegral(f(x,y,z), Eq(2 - 3*x + x*2, z), normal=-z) |
How does Mathematica handle that? |
The implicit definition of an integral is probably a very difficult problem. That was just an idea to represent the integral in a nice way, but if it's too hard to manage, we can abandon that idea. There are other ways to represent an integral. An other possibility is to just support a few simple implicitly-defined integrals. |
@Upabjojr It seems that it uses the dimension of the region and whether the implicit region is defined in terms of equation or inequality. But it also uses some other technique that I have not yet figured out. It is pretty intelligent. Mathematica's doc:
|
If we can get the parametric representation of the surface from its implicit equation, we can get the result. |
A surface integral does not necessarily need to depend on the orientation. For example you might integrate the density of charge (a scalar field) around the surface of a conductor to get the total charge. A surface integral of a vector field (I would call this a "flux integral") depends on the orientation of the surface. If the calculation of the dot-product with unit normal is handled by the user then the orientation does not need to be guessed and sympy just needs to evaluate surface integrals of scalar fields. Is that how mathematica handles orientation? |
Yes, we do not need the orientation for integrating Scalar Fields over surfaces.
@oscarbenjamin This looks like a good idea. Sympy can just return the absolute value of flux and the user can determine the sign themselves.
I have not found yet how Mathematica determines orientation. I have found only a few problems of flux on Mathematica. The user does not have to specify the orientation. Unfortunately, I do not have Mathematica myself. I will post here once I find it. |
The answer in the SO question you link to suggests that it is left to the user to find the normal vector and compute the dot product so that Mathematica's integrate only does scalar surface integrals. |
With the equation solver somehow. I believe that the general algorithm is very hard. However, that's not important, one step at a time. |
I don't think that scalar field integrals are invariant under orientation. I only found that there are actually two types of integrals, one should depend on the orientation and the other should not depend on the orientation. When I read https://www.math.purdue.edu/~arapura/preprints/diffforms.pdf, I see that there is definition 3.4.1 which introduces the notation of integrals over metric tensor, and other integral notation that uses wedge products of differential forms. If it uses some differential forms with wedge product notation, it should depend on the orientation, and if it uses metric tensor, it takes absolute value so it should not depend on the orientation. But for the vector integrals, they both depend on the orientation because even for integration over metric tensor, it cancels out the absolute value term. So I think that And for parametric regions, we should be more clear about the orientation because it has native parameterization that can induce its own orientation. |
When converting from a surface integral to an iterated integral the limits need to be chosen carefully to ensure that the iterated integral has the same sign as the surface integral. The surface integral itself does not have limits in the same way that an iterated integral has (the limits are the curves representing the boundaries of the surface). As I would define it the surface integral of a nonnegative scalar field
That is for a line integral and yes absolutely the sign of a line integral is reversed by reversing the direction. A surface integral does not have a "direction". A surface may be "orientable" which is to say that it is possible to choose between one of two different consistent definitions for the surface normal.
Agreed. With the standard formulas the order of the parameters in the parametrisation implies a choice of orientation. |
Maybe we can always return the absolute value of the iterated integral or the sign of the integral should as that of the scalar field. |
You can always just multiple by I do think though that a surface integral should have the correct sign if the parametric limits are correctly ordered. |
For a parametric region, I think the bounds should be in the same order as specified by the user. |
I joined SymPy in 2012, and that was an open issue. After 8 years we still don't have a way to represent that kind of assumptions. |
The Vector module does not have support to perform integration of vector/scalar fields over curves, surfaces, and volume.
Integral
class represents integration over variables. It cannot handle Vector integrals. We need to implement subclasses ofIntegral
.Also, go through sympy/vector gitter room.
The text was updated successfully, but these errors were encountered: