Problem with line integrals in Mathematica

In summary: Does this make sense?In summary, the conversation discusses the use of Mathematica to calculate line integrals over a straight line from point (0,0) to (2,3) using three different parametrizations. However, each parametrization yields a different result, causing confusion. It is noted that the first integral is actually a double integral and the correct parametrization for the line integral should include a parametrization of the path length ds. The conversation also discusses a second example of a line integral from (2,3) to (5,4) using two different parametrizations, which also yields different results. It is suggested to parametrize r and theta with a parameter t to properly calculate ds along the
  • #1
Frank Einstein
170
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
  • #2
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 Frank Einstein
  • #3
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.
 
  • #4
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.
 
  • #5
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)
 
  • #6
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 Frank Einstein
  • #7
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.
 
  • #8
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 Frank Einstein
  • #9
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:
  • #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.
 

1. What is a line integral in Mathematica?

A line integral in Mathematica is a mathematical concept that involves calculating the integral of a function along a specified curve in two or three dimensions. It is typically used in fields such as physics, engineering, and mathematics to solve problems involving work, circulation, and flux.

2. Why do I encounter problems when using line integrals in Mathematica?

There can be several reasons for encountering problems with line integrals in Mathematica. Some common issues include incorrect syntax, incorrect input of the curve or function, or the function being undefined at certain points along the curve.

3. How can I fix errors when using line integrals in Mathematica?

To fix errors when using line integrals in Mathematica, it is important to carefully check the syntax and input of the function and curve. It may also be helpful to use the built-in documentation or seek assistance from online resources or forums.

4. Can Mathematica handle complex line integrals?

Yes, Mathematica has the capability to handle complex line integrals. It has a wide range of built-in functions and tools that can be used to solve complex line integrals, making it a powerful tool for mathematicians and scientists.

5. Are there any tips for efficiently using line integrals in Mathematica?

One helpful tip for efficiently using line integrals in Mathematica is to use vectorized functions, which allow for faster calculations and can handle large amounts of data. It is also important to familiarize oneself with the syntax and available functions in Mathematica to optimize the use of line integrals.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
228
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
268
  • MATLAB, Maple, Mathematica, LaTeX
Replies
13
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • Calculus and Beyond Homework Help
Replies
10
Views
456
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
Back
Top