Problem with line integrals in Mathematica

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
9 replies · 4K views
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.
 
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:
[tex]\int_0^3 \int_0^2 \frac{e^{-(x^2+y^2)}}{16 \pi} dx dy[/tex]
 
  • 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:
[tex]\int_0^3 \int_0^2 \frac{e^{-(x^2+y^2)}}{16 \pi} dx dy[/tex]

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 [itex]ds = \sqrt{2^2 + 3^2} dt[/itex], 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 [itex]ds = \sqrt{2^2 + 3^2} dt[/itex], 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, [itex]x^2 + y^2 = r^2[/itex], so you don't need the sin and cos terms. This should be obvious since [itex]sin^2(x) + cos^2(x) = 1[/itex]
 
  • Like
Likes   Reactions: Frank Einstein
phyzguy said:
Also, in your second case, [itex]x^2 + y^2 = r^2[/itex], so you don't need the sin and cos terms. This should be obvious since [itex]sin^2(x) + cos^2(x) = 1[/itex]
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:
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.