Problem with line integrals in Mathematica

Click For Summary

Discussion Overview

The discussion revolves around the calculation of line integrals using Mathematica, specifically comparing results obtained from different parametrizations for a two-dimensional Gaussian random variable. Participants explore the implications of parametrization choices and the correct application of line integrals versus double integrals.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant presents three different parametrizations for a line integral from (0,0) to (2,3) and notes differing results, questioning the correctness of their approach.
  • Another participant points out that the first integral presented is a double integral, not a line integral, which may explain the discrepancy in results.
  • There is a discussion about the need to include a proper parametrization of the path length ds in line integrals, with suggestions that the participant's second parametrization may be incorrect.
  • One participant mentions using the Jacobian to switch between Cartesian and polar coordinates, but another challenges this by stating that the Jacobian for area integrals is not appropriate for line integrals.
  • Participants discuss the relationship between r, dr, and the need to adjust the parametrization to reflect the path taken in the integral.
  • A later post introduces a new problem involving a different line integral from (2,3) to (5,4), again noting discrepancies in results and questioning the need for additional elements in the parametrization.

Areas of Agreement / Disagreement

Participants generally agree that the first integral is a double integral and not a line integral. However, there remains disagreement regarding the correct parametrization for the second case and whether additional elements are necessary for the new problem presented.

Contextual Notes

There are unresolved issues regarding the correct application of parametrizations in line integrals, particularly concerning the relationship between Cartesian and polar coordinates and the appropriate use of the Jacobian. The discussion highlights the complexity of transitioning between different coordinate systems and the implications for integral results.

Frank Einstein
Messages
166
Reaction score
1
Hello everyone. I am testing mathematica to work with some line integrals. I want to go from the point (0,0) to (2, 3) over a straight line. I do it with 3 different parametrizations. The problem is that each one offers me a different result. The original problem is a two dimensional gaussian random variable.

varianza=2;

Integrate[(1.)*Exp[(-1.)*(x^2 + y^2)/(2.*varianza)]/(2*Pi*varianza), {x, 0, 2}, {y, 0, 3}].
The result is 0.203534.

The first reparametrization is x=2*t, y=3*t, t∈[0,1]
Integrate[(Sqrt[2^2 + 3^2]* Exp[(-1.)*((2*t)^2 + (3*t)^2)/(2.*varianza)]/(2*Pi*varianza)), {t,
0, 1}].
The result is 0.139526.

The second is done by using polar coordinates, r∈[0,sqrt(2²+3²)] and θ=ArcTan[3/2].

angulo = ArcTan[2, 3];
Integrate[(r*Exp[(-1.)*((Cos[angulo]*r)^2 + (Sin[angulo]*r)^2)/(2.*varianza)]/(2*Pi*varianza)), {r, 0, Sqrt[2^2 + 3^2]}]
The result is 0.152984.

Shoudn't the value of all three integrals be the same? If that is the case, what am I doing wrong?

Thanks for reading.
 
Physics news on Phys.org
Note that your first integral is not a line integral, it is a double integral. In the first one, what you have asked Mathematica to do is to calculate:
\int_0^3 \int_0^2 \frac{e^{-(x^2+y^2)}}{16 \pi} dx dy
 
  • Like
Likes   Reactions: Frank Einstein
phyzguy said:
Note that your first integral is not a line integral, it is a double integral. In the first one, what you have asked Mathematica to do is to calculate:
\int_0^3 \int_0^2 \frac{e^{-(x^2+y^2)}}{16 \pi} dx dy

I see. Thanks for your answer. However, I still have a problem with equations 2 and 3. I don't know if my parametrization is incorrect or if this is due to numerical errors.
 
When you're doing a line integral, you need to include a parametrization of the path length ds. I think you have done this correctly in the first line integral, with ds = \sqrt{2^2 + 3^2} dt, but I don't think you have done this correctly in the second case. How would you write ds in terms of dθ in the second case?

Edit: The difference is definitely not due to numerical errors.
 
phyzguy said:
When you're doing a line integral, you need to include a parametrization of the path length ds. I think you have done this correctly in the first line integral, with ds = \sqrt{2^2 + 3^2} dt, but I don't think you have done this correctly in the second case. How would you write ds in terms of dθ in the second case?

Edit: The difference is definitely not due to numerical errors.

In the second case, I use the Jacobian to swich between cartesian and polar coordinates, in this case, it's value is r, the radial coordinate. The angle is constant here and equal to ArcTan[2,3].

That is what I have: Jacobian(r)*f(r)*dr between 0 and (x^2+y^2)
 
That's not correct. The r*dr*dθ Jacobian is for an area integral. It's because the area is a small square that is dr on one side and r*dθ on the other side. In the case you have, as you said, θ=constant, so you just have ds = dr. You don't need the factor of r. Do you agree?
 
  • Like
Likes   Reactions: Frank Einstein
phyzguy said:
That's not correct. The r*dr*dθ Jacobian is for an area integral. It's because the area is a small square that is dr on one side and r*dθ on the other side. In the case you have, as you said, θ=constant, so you just have ds = dr. You don't need the factor of r. Do you agree?

I haven't thought of that. I will chech the theory again and code it tomorrow since I haven't acess to mathematica right now.

Thank you so much.
 
Also, in your second case, x^2 + y^2 = r^2, so you don't need the sin and cos terms. This should be obvious since sin^2(x) + cos^2(x) = 1
 
  • Like
Likes   Reactions: Frank Einstein
phyzguy said:
Also, in your second case, x^2 + y^2 = r^2, so you don't need the sin and cos terms. This should be obvious since sin^2(x) + cos^2(x) = 1
I have removed the r from the jacobian and both results are equal. Thanks for your help. However, may I ask you about another issue I am having right now?

Now, I am trying to move the particle from (2, 3) to (5, 4) again using a straight line.

For the first parametrization, x=3*t+2 and y=3+t. For the second, the radius goes between Sqrt[2^3+3^2] and Sqrt[5^2+4^2] and the values are again different.

Integrate[(Sqrt[(3)^2 + (1)^2]*Exp[(-1.)*((3*t + 2)^2 + (t + 3)^2)/(2.*varianza)]/(2*Pi* varianza)), {t, 0, 1}]
0.00182929

and

Integrate[(Exp[(-1.)*r^2/(2.*varianza)]/(2*Pi*varianza)), {r, Sqrt[(2)^2 + (3)^2], Sqrt[(5)^2 + (4)^2]}]
0.0015207

I think that this has to do with the fact that since I am not moving from the centre I am changing my angle, but it doesn't appear on my equation and the line is still straight, so I wouldn't have to introduce any new elements right?

Thanks again.
 
Last edited:
  • #10
Frank Einstein said:
I have removed the r from the jacobian and both results are equal.

Good, so that is all clear now.

I think that this has to do with the fact that since I am not moving from the centre I am changing my angle, but it doesn't appear on my equation and the line is still straight, so I wouldn't have to introduce any new elements right?

Why do you think that you, "wouldn't have to introduce any new elements"? What you calculated in your second integral was the line integral from the point (2,3) to the point with r=sqrt(41) along a constant theta. This isn't what you want to do. To do what you want, you would need to parametrize r and theta with some parameter t, like you did in the first example, and then calculate ds along this parametrized line. It might help for you to draw out the line integral in each case.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 19 ·
Replies
19
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K