Wikipedia:Reference desk/Archives/Mathematics/2020 June 23

= June 23 =

Curve fitting
What mathematical shape fits the part of the southeast Mediterranean that looks like a curve best? Sagittarian Milky Way (talk) 17:57, 23 June 2020 (UTC)


 * The whole border of the Mediterranean is one very long curve. Given a precise specification of what should be approximated from where to where, it can be approximates to any desired precision by a mathematical shape. Without further constraints, the question has no answer. An example of a constrained problem could be: what elliptic arc offers the best approximation of the Mediterranean coastline from Tobruk to Alexandria. Even then, there are several reasonable candidates for measuring the goodness of fit (among which the little-known Hausdorff distance has good papers); different measures will produce different optimal fits. --Lambiam 18:36, 23 June 2020 (UTC)


 * From before the bumpity bump near Haifa south till either the point in Sinai where the latitude stops decreasing or up to a few miles before that if that fits much better. I do not know if the best elliptic curve is better than the best parabola, y=x^z etc. if I did I would've only wondered about which ellipse. I'm not wondering about complex curves like polynomials with many terms, only relatively simple ones or ones commonly used for curve fitting (but not long equations like those polynomials). For fit I will say minimizing the maximum distance between a point on the coast and the nearest point on the curve, with the endpoints on the coast. I've always thought that part of the coast resembled something mathematical and not too "overfitted looking" and it's aesthetic to me and I wonder what it is. Sagittarian Milky Way (talk) 20:33, 23 June 2020 (UTC)


 * After smoothing out the tiny bumps and kinks along that stretch, so that you get a sleek slide down the coast, you obtain a swooshy curve for which the curvature changes very gradually and seemingly uniformly along the length of the curve. I guess this is the property that you find aesthetically pleasing, rather than this curve being representable by some particular simple mathematical shape. If the purpose is to describe the shape parsimoniously yet accurately, then splines are the tool of choice. Ellipses and parabolae are both conic sections; I bet you can get a reasonably good fit with a parabolic arc and a slightly better one with an elliptic arc. But perhaps some of the well-known spirals, such as the Archimedean spiral or the Euler spiral, will give an even better fit. You can also fiddle with the map projection – Mercator, Lambert conformal conic, Werner, ... – each will give a different best fit. The main practical problem in trying to find a tight fit, other than the plethora of options, may be to obtain a digital file of the coordinates of that stretch of coastline. --Lambiam 09:40, 24 June 2020 (UTC)
 * Can you do it on a sphere or ellipsoid? Are the simplish curve types all well-defined on a sphere or ellipsoid? How many points will probably be enough if collecting the points manually? (manually also makes sure there aren't database errors and allows human judgement on what shouldn't be included i.e. anything artificial-looking like piers, sand caught by jetty and so on) What's the most efficient way to space the points? Equal distance apart? Is spending time on getting more points better than spending extra seconds equalizing distance to the last point? Is x points as good as you can do at max practical satellite layer zoom better than x+y points to the nearest z feet? Best balance of point numerousness and accuracy that is. Or if say 102to 102.5 points very accurate, roughly evenly spaced is enough then I could just not care about quickest balance of count and accuracy and collect points as accurate as I can. Do you have a recommendation on best software to do this in on Windows, Android and website? (my phone is full) How do I move the origin and/or rotate the coordinate frame of the final equation to make the equation simplest? I was truant every millisecond the last 2.5 grades and a little before and only learned the boring side of school enough to get Ds and Cs so if I should've learned that in school this is why. Sagittarian Milky Way (talk) 17:39, 24 June 2020 (UTC)
 * That is a lot of questions. Curves on non-flat surfaces are not an extensively studied subject. It is, of course, possible to take a plane curve and apply an inverse map projection to get a curve on a sphere. The segment in question being rather small in comparison to the size of Earth (about 200 km on a radius of 6370 km, corresponding to a hump of less than 800m compared to a straight line between the end points), I don't see why one should bother. The ellipsoidal aspect of the shape of Earth is even less consequential. Take the local radius of curvature as a measure – which can be estimated by putting a coin or small circular lid so that the curve bends somewhat equidistantly around it and taking the distance of the coin centre to the curve. If the desired precision as a fraction of that radius is $$p$$, then the distance between the points should locally not be larger than a fraction of $$\sqrt{8p}$$ of the radius. For example, let the desired precision be 1 mm . If the local radius of curvature is 120 mm, that corresponds to a relative precision of $$p = \tfrac{1}{120}$$. The relative distance between successive points should then not exceed $$\sqrt{\tfrac{8}{120}}$$ times the radius, or 0.25+ times 120 mm, which is slightly more than 3 mm. Equalizing distances is not important; not leaving large gaps between points is. So spend the time on keeping the largest distance small – and smaller where the curvature is high. I have no idea what available software could help with the optimizations; I am not at all familiar with Wolfram Mathematica and have no idea of its capabilities. If this was my personal project I'd just write the necessary programs from scratch. If you are going for a conic section defined by a formula of the form $$\Sigma c_{i,j}x^i y^j = 0$$, you can do a translation to make the linear coefficients vanish, ending up with something of the form $$c_{2,0}x^2 + c_{1,1}xy + c_{0,2}y^2 + c_{0,0} = 0$$. A rotation can then get rid of the $$

c_{1,1}xy$$ term. You can do this by substituting $$x^\prime\cos\theta+y^\prime\sin\theta$$ for $$x$$ and $$-x^\prime\sin\theta+y^\prime\cos\theta$$ for $$y$$, rewriting the resulting lhs in the form $$c^\prime_{2,0}x^{\prime 2} + c^\prime_{1,1}x^\prime y^\prime + c^\prime_{0,2}y^{\prime 2} + c^\prime_{0,0}$$, in which the coefficient $$c^\prime_{1,1}$$ will be an expression involving $$\theta$$, and then solving $$c^\prime_{1,1} = 0$$ for $$\theta$$. I don't think this is something you'd learn in high school. All together not something to do in a lost moment; your main reward after all the frustration may be that in the end you acquired some mathematical skill. --Lambiam 21:20, 24 June 2020 (UTC)
 * Maybe it's easier to just type my points into something I can set to subtract a constant I can set from each x and a different constant from each y before pasting those points into the curve fitter, it might also be able to multiply each longitude by the cosine of (max lat+min lat)/2 which is needed for a reasonable conversation from geographic to Cartesian anyway. Sagittarian Milky Way (talk) 18:20, 25 June 2020 (UTC)
 * Subtracting a constant and multiplying by a constant both change the scale according to a linear function. That will not make the task in any way easier for curve fitting software. For plotting without too much distortion, you do indeed need to adjust the scales using the cosine of the latitude. --Lambiam 20:39, 25 June 2020 (UTC)
 * It will make the task easier for someone with poor math skills like me to neither have to understand how to move the shape with equation surgery nor manually subtract latitudes and manually cosine corrected longitudes from each point before feeding into the curve fitter if I could just type it into a web form or software that's like the Single Instruction Multiple Data of data entry. And then copy those to paste into the curve fitter. If my uneducated guess of putting the Sinai endpoint of no slope at the origin is wrong for any of these equation types then trial and error to try to find the focus or whatever's the right point will be a pain in the ass without being able to try different offsets quickly. Or maybe I can still understand how to strip the positioning or rotation data from the equation if it's explained to me in something that's more English and less mathese. It's probably trivial in English or lower grade math. Sagittarian Milky Way (talk) 21:08, 25 June 2020 (UTC)
 * And you're right it might be a spiral. I always thought the curvature looks decreasing towards Haifa and one of the things I was picturing is apparently called a Euler spiral. I always wondered if the curvature would go to zero if continued and what the slope would be. Sagittarian Milky Way (talk) 21:21, 25 June 2020 (UTC)

The general subject of curve fitting falls under interpolation and numerical analysis. If you are willing to allow piecewise curves, a cubic spline interpolation of carefully chosen points would look great.--Jasper Deng (talk) 08:50, 25 June 2020 (UTC)
 * Even more useful would be specific techniques used in curve-fitting such as Fourier analysis (which can decompose curves into an arbitrary series of cyclic (sine) functions) and Taylor series (which can decompose curves into an arbitrary series of polynomial functions). Broadly speaking, whether using cyclic functions or polynomial functions, or some combination thereof, any arbitrary curve can be decomposed into a function, limited only be the tolerances of your approximation.  If you wanted to write an equation to recreate a specific coastline, you just need to define how "close" you want the resulting function to be, then you can create it using these analytical tools.  (see, also relevant here, the coastline paradox, which is a consequence of this property.)  -- Jayron 32 19:24, 25 June 2020 (UTC)
 * This is similar to something I wondered in high school, whether you could approximate any island or obscenely asymmetrical squiggle with a billion turns (possibly excluding ones that cross themselves or have infinitely sharp corners or maybe even that too) to any accuracy with a single equation though it might be longer than a book. You're saying it can be done with a series of equations which is trivially obvious, even simple linear equations can have lines at any slope. If each piece of curve is a piece of a different conic section then how is that elegant, as accurate as it might be? Likewise I see astronomical squiggles approximated with things something like y=230.336787337888+3.7679243676768x-0.94647685735x**2+0.109866376458x**3 ... 0.00000000534747x**14 which is a single equation. I'm thinking a simple shape like a conic section or maybe y=x**a or y=a**x or those things with logs (if you translate and (if needed) rotate or reflect the shape to the right way) can still be very close which is more elegant and less unremarkable than simply brute forcing it with tons of terms or even multiple equations. Sagittarian Milky Way (talk) 20:30, 25 June 2020 (UTC)


 * Would a graph of the shoreline's curvature as a function of arc-length help identify the simple function most closely resembling the shoreline? -- ToE 01:30, 26 June 2020 (UTC)
 * In some special cases it would. Obviously, a constant curvature means a circular arc. If the curvature increases or decreases linearly with the arc-length, we have a segment of an Euler spiral. But for most simple curves the function that produces the curvature given the arc-length is not simple at all and not particularly recognizable from its shape. --Lambiam 02:47, 26 June 2020 (UTC)


 * I took the Commons 1250×1600 px bitmap of the East coast of the Mediterranean and interpreted the coastline as a graph. Keeping pixels as the unit of measure, we can impose an $$(x,y)$$ coordinate system whose origin $$(x,y)=(0,0)$$ corresponds to $$(h,v)=(290,1397)$$ (the southmost point along the coastline before it veers up again when moving to the West), with $$x$$ increasing to the East (just like $$h$$) and $$y$$ increasing to the North (contrary to $v$). Taking only the part from $$(0,0)$$ to $$(234,342),$$ I determined the best fit with a parabola $$y=cx^2,$$ which resulted in $$y=0.00548 x^2$$ with a max deviation of $$14.9$$ – not a good fit. Allowing other exponents than $$2$$ gave a best fit for $$y=0.00016008 x^{2.6695}$$ with a max deviation of $$8.7$$ – better, but still not very good. --Lambiam 22:08, 26 June 2020 (UTC)
 * So maybe simple image editors and a curve fitter I found are enough, I remember Microsoft Paint or Gimp or something showed the x and y positions of the cursor, and they can edit Google Maps screenshots so the raw pixel coordinates are pre-adjusted. Sagittarian Milky Way (talk) 14:47, 27 June 2020 (UTC)
 * The prospects for a fit with an Euler spiral do not look good. A plot of estimated curvature versus estimated arc-length looks like a rollercoaster ride. --Lambiam 17:45, 28 June 2020 (UTC)
 * Do any large sections look like something? Eyeballing it with a better map it looks like from the curvature change near Beersheba latitude to the bump at about Nazareth's latitude is the most consistent part. Sagittarian Milky Way (talk) 14:35, 29 June 2020 (UTC)
 * Not really. No substantive section of the plot looks linear. The part you identify is less wavy (lower amplitude, fewer bumps) but has no familiar shape – although it is reminiscent of the elephant swallowed by a boa. --Lambiam 15:53, 29 June 2020 (UTC)


 * You might get more helpful answers if you explained why you are trying to do this (i.e., once you choose a curve that approximates the coastline, you will use that curve to ...). --JBL (talk) 17:05, 29 June 2020 (UTC)


 * Once you've found a proof of the Collatz conjecture, you will use that proof to ... What about pursuing something because it is interesting, without an ulterior utilitarian goal?  --Lambiam 21:50, 29 June 2020 (UTC)


 * Evidently you can read minds, but as a mere professor of pure mathematics, I content myself with reading the words people write. --JBL (talk) 00:03, 30 June 2020 (UTC)
 * "I've always thought that part of the coast resembled something mathematical and not too 'overfitted looking' and it's aesthetic to me and I wonder what it is ." ... "I'm thinking a simple shape like a conic section or maybe y=x**a or y=a**x ... can still be very close which is more elegant and less unremarkable than simply brute forcing it ...". It just takes the ability to read texts to see there is no utilitarian goal here. --Lambiam 09:41, 30 June 2020 (UTC)