Wikipedia:Reference desk/Archives/Mathematics/2024 April 13

= April 13 =

How to calculate a line integral by computer?
Hi!

There is a line integral ∫L yds, where L is y2=2x and from (1/2, -1) to (2, 2). My answer is (5√5−2√2)/3, but L is a quadratic curve (instead of a line) and the answer seems odd, therefore I am not sure my calculation is correct or not.

How can I calculate a line integral result by computer (by Wolfram Alpha, python etc.)? James King 2009 (talk) 11:49, 13 April 2024 (UTC)


 * Swapping $$x$$ and $$y$$, this is the arc length of the segment of the parabola given by the equation $$y=\frac12 x^2$$ from $$x=-1$$ to $$x=2$$. It can be turned into an ordinary integral of the form
 * $$L=\int_a^b\sqrt{1 + \left(\frac{dy}{dx}\right)^2}dx.$$
 * In view of the square root in this formula, the appearance in the result should not be odd, but I find a different result, involving not only square roots but also logarithms (or arcsines). Obviously, the length of the arc should exceed that of the straight line segment connecting the end points, which is $$\tfrac32\sqrt5>3.35,$$ but your result evaluates numerically to less than $$2.79.$$ To check your result: its numerical value should be close to $$4.10568.$$ --Lambiam 14:19, 13 April 2024 (UTC)
 * The question calls for the integral of yds, so the first moment wrt the x-axis, not arc length. So basically you're integrating $$\int y \sqrt{1 + y^2} dy$$. --RDBury (talk) 15:37, 13 April 2024 (UTC)
 * PS. if you just want a ballpark estimate to check your result, break the curve up and approximate by line segments. In this case the section from y=-1 to y=1 cancels itself out, so you really just have to do the segment from (1/2, 1) to (2, 2). If you replace the curve with a line segment, its center of mass is the midpoint, so (5/4, 3/2). The length is √13/2, so the moment is (3/2)(√13/2) ≈ 2.7. That's off from the original result by about .1 so I'd count it as verified. --RDBury (talk) 15:54, 13 April 2024 (UTC)
 * Symbolic integration by Maxima confirms it as well. --Lambiam 20:54, 13 April 2024 (UTC)
 * Actually I should try that out, so thanks. There are limits to what you can do with pencil & paper (and maybe a calculator). I've found you can do wonders with an off-the-shelf spreadsheet program, and if you already know how to use one that would work as well. As with many things, the trade-off is the time it takes to learn how to use the tool in question. You can write a Python program when the task is too complex for a spreadsheet, but if you don't know Python already that's a lot of effort for solving one problem. The OP mentioned Wolfram Alpha as well, and I assume that would tell you the answer too if you know the right input string. I use Alpha occasionally, but mostly for things where the right command is obvious, "solve x^3-x-1=0" for example. --RDBury (talk) 02:17, 14 April 2024 (UTC)
 * For this specific integral it isn't too hard to do the integration purely mentally by change of variables $$(\sqrt{1{+}y^2}\leftrightarrow u,$$ so $$d(1{+}y^2)=d(u^2)$$ and thus $$y\,dy=u\,du).$$ --Lambiam 10:09, 14 April 2024 (UTC)