I am trying to compute the arc length along a curve given by parametric 
functions x and y in t. To do this I want to integrate along the curve 
using:


t = var('t')
def arc_length(x,y, pts):
    """ Return the arc length along a parametric curve give two parametric
    functions `x` and `y` in `t` between `t=0` and `t`=`pts`
    """
    return integrate(sqrt(x.derivative()**2 + y.derivative()**2), t, 0, pts)

This works fine for "small" functions x and y such as:

x1 = 
4/21*cos(34/19-(1753*t)/31)+4/19*cos(117/47-(1709*t)/34)+13/43*cos(82/27-(2419*t)/55)+847/57*cos(59/44-(289*t)/46)+9/14*cos((377*t)/30+53/27)+57/31*cos((377*t)/20+65/31)+51/41*cos((377*t)/15+40/39)+19/31*cos((377*t)/12+27/22)+22/37*cos((377*t)/10+5/13)+129057/86

y1 = 
165/68*cos(35/22-(377*t)/30)+247/32*cos((289*t)/46+148/57)+10/27*cos((377*t)/20+20/27)+29/48*cos((377*t)/15+34/15)+15/32*cos((377*t)/12+30/11)+13/29*cos((377*t)/10+35/18)+9/22*cos((2375*t)/54+31/21)+12/23*cos((1709*t)/34+12/11)+9/23*cos((1753*t)/31+47/24)+2719/31

with

sage: arc_length(x1,y1,10)

which returns 877.411966839000

When I try doing the same thing with 20 points it, first, takes an awfully 
long time and, secondly, fails with the error:

Adaptive method failure, will try with Romberg, last approximation was 
1900.48157796
Unable to find numeric integral using Romberg method, returning the last 
approximations

Is there a more intelligent way to do this? All of the code is attached and 
the second failing example is below..

Andrew
----
Here are the points that this fails on:

x2= 
2/9*cos(37/14-(3506*t)/31)+5/26*cos(71/27-(3217*t)/32)+4/21*cos(34/19-(1753*t)/31)+4/19*cos(117/47-(1709*t)/34)+13/43*cos(82/27-(2419*t)/55)+847/57*cos(59/44-(289*t)/46)+9/14*cos((377*t)/30+53/27)+57/31
 
*cos((377*t)/20+65/31)+51/41*cos((377*t)/15+40/39)+19/31*cos((377*t)/12+27/22)+22/37*cos((377*t)/10+5/13)+5/41*cos((4461*t)/71+3/20)+3/13*cos((1797*t)/26+91/30)+7/32*cos((5504*t)/73+48/19)+7/38*cos((1797*t)/22+61/21)+2/25*cos((2463*t)/28+7/22)+7/39*cos((7634*t)/81+57/29)+1/8*cos((2884*t)/27+69/22)+1/19*cos((2507*t)/21+16/13)+129057/86

y2=5/41*cos(23/25-(3506*t)/31)+6/41*cos(42/125-(3217*t)/32)+5/29*cos(23/33-(2463*t)/28)+3/35*cos(24/25-(1797*t)/22)+3/19*cos(5/22-(6258*t)/83)+2/19*cos(9/41-(1797*t)/26)+1/37*cos(106/47-(5215*t)/83)+165/68*cos(35/22-(377
 
*t)/30)+247/32*cos((289*t)/46+148/57)+10/27*cos((377*t)/20+20/27)+29/48*cos((377*t)/15+34/15)+15/32*cos((377*t)/12+30/11)+13/29*cos((377*t)/10+35/18)+9/22*cos((2375*t)/54+31/21)+12/23*cos((1709*t)/34+12/11)+9/23*cos((1753*t)/31+47/24)+4/29*cos((7634*t)/81+133/43)+5/38*cos((2884*t)/27+317/136)+1/10*cos((2507*t)/21+20/17)+2719/31

arc_length(x2,y2,20)


-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-support/e0fbf5ce-07bb-4e94-8d57-18c6108a2fa1n%40googlegroups.com.
t = var('t')

def arc_length(x,y, pts):
    """ Return the arc length along a parametric curve give two parametric
    functions `x` and `y` in `t` between `t=0` and `t`=`pts`
    """
    return integrate(sqrt(x.derivative()**2 + y.derivative()**2), t, 0, pts)

x1 = 4/21*cos(34/19-(1753*t)/31)+4/19*cos(117/47-(1709*t)/34)+13/43*cos(82/27-(2419*t)/55)+847/57*cos(59/44-(289*t)/46)+9/14*cos((377*t)/30+53/27)+57/31*cos((377*t)/20+65/31)+51/41*cos((377*t)/15+40/39)+19/31*cos((377*t)/12+27/22)+22/37*cos((377*t)/10+5/13)+129057/86

y1 = 165/68*cos(35/22-(377*t)/30)+247/32*cos((289*t)/46+148/57)+10/27*cos((377*t)/20+20/27)+29/48*cos((377*t)/15+34/15)+15/32*cos((377*t)/12+30/11)+13/29*cos((377*t)/10+35/18)+9/22*cos((2375*t)/54+31/21)+12/23*cos((1709*t)/34+12/11)+9/23*cos((1753*t)/31+47/24)+2719/31

print('L1: ', arc_length(x1,y1,10)

x2= 2/9*cos(37/14-(3506*t)/31)+5/26*cos(71/27-(3217*t)/32)+4/21*cos(34/19-(1753*t)/31)+4/19*cos(117/47-(1709*t)/34)+13/43*cos(82/27-(2419*t)/55)+847/57*cos(59/44-(289*t)/46)+9/14*cos((377*t)/30+53/27)+57/31 *cos((377*t)/20+65/31)+51/41*cos((377*t)/15+40/39)+19/31*cos((377*t)/12+27/22)+22/37*cos((377*t)/10+5/13)+5/41*cos((4461*t)/71+3/20)+3/13*cos((1797*t)/26+91/30)+7/32*cos((5504*t)/73+48/19)+7/38*cos((1797*t)/22+61/21)+2/25*cos((2463*t)/28+7/22)+7/39*cos((7634*t)/81+57/29)+1/8*cos((2884*t)/27+69/22)+1/19*cos((2507*t)/21+16/13)+129057/86

y2=5/41*cos(23/25-(3506*t)/31)+6/41*cos(42/125-(3217*t)/32)+5/29*cos(23/33-(2463*t)/28)+3/35*cos(24/25-(1797*t)/22)+3/19*cos(5/22-(6258*t)/83)+2/19*cos(9/41-(1797*t)/26)+1/37*cos(106/47-(5215*t)/83)+165/68*cos(35/22-(377 *t)/30)+247/32*cos((289*t)/46+148/57)+10/27*cos((377*t)/20+20/27)+29/48*cos((377*t)/15+34/15)+15/32*cos((377*t)/12+30/11)+13/29*cos((377*t)/10+35/18)+9/22*cos((2375*t)/54+31/21)+12/23*cos((1709*t)/34+12/11)+9/23*cos((1753*t)/31+47/24)+4/29*cos((7634*t)/81+133/43)+5/38*cos((2884*t)/27+317/136)+1/10*cos((2507*t)/21+20/17)+2719/31

print('L2: ', arc_length(x2,y2,20)

x3= 1/33*cos(29/15-(8143*t)/27)+1/62*cos(80/29-(8564*t)/29)+1/24*cos(51/64-(10694*t)/37)+1/38*cos(151/84-(9896*t)/35)+1/119*cos(3/35-(10229*t)/37)+1/22*cos(124/41-(4593*t)/17)+1/23*cos(5/26-(7477*t)/35)+2/25*cos(5/3-(6013*t)/29)+1/43*cos(3/25-(3217*t)/16)+4/35*cos(15/11-(1753*t)/9)+2/29*cos(15/46-(6013*t)/33)+1/23*cos(79/36-(2463*t)/14)+1/34*cos(76/31-(5259*t)/31)+3/31*cos(164/57-(1797*t)/11)+1/10*cos(15/14-(5347*t)/37)+1/18*cos(20/11-(1797*t)/13)+4/31*cos(44/39-(2507*t)/19)+6/53*cos(9/5-(12315*t)/98)+2/9*cos(37/14-(3506*t)/31)+5/26*cos(71/27-(3217*t)/32)+4/21*cos(34/19-(1753*t)/31)+4/19*cos(117/47-(1709*t)/34)+13/43*cos(82/27-(2419*t)/55)+847/57*cos(59/44-(289*t)/46)+9/14*cos((377*t)/30+53/27)+57/31*cos((377*t)/20+65/31)+51/41*cos((377*t)/15+40/39)+19/31*cos((377*t)/12+27/22)+22/37*cos((377*t)/10+5/13)+5/41*cos((4461*t)/71+3/20)+3/13*cos((1797*t)/26+91/30)+7/32*cos((5504*t)/73+48/19)+7/38*cos((1797*t)/22+61/21)+2/25*cos((2463*t)/28+7/22)+7/39*cos((7634*t)/81+57/29)+1/8*cos((2884*t)/27+69/22)+1/19*cos((2507*t)/21+16/13)+1/329*cos((6635*t)/44+5/21)+1/18*cos((3927*t)/25+95/36)+1/42*cos((17530*t)/93+76/61)+1/36*cos((7477*t)/34+97/44)+2/33*cos((8143*t)/36+25/46)+1/68*cos((5347*t)/23+5/11)+1/53*cos((5014*t)/21+11/7)+1/45*cos((5636*t)/23+11/30)+1/134*cos((12315*t)/49+10/21)+1/26*cos((4637*t)/18+72/23)+1/42*cos((5014*t)/19+80/29)+1/40*cos((20012*t)/65+22/13)+129057/86

y3=1/130*cos(5/4-(27401*t)/89)+1/87*cos(111/43-(8143*t)/27)+1/97*cos(34/13-(9896*t)/35)+1/37*cos(97/38-(10229*t)/37)+3/40*cos(61/44-(7477*t)/34)+1/23*cos(24/23-(6013*t)/29)+1/54*cos(11/15-(1753*t)/9)+1/12*cos(91/33-(1797*t)/11)+2/41*cos(51/37-(6635*t)/44)+1/23*cos(40/13-(1797*t)/13)+1/23*cos(33/17-(12315*t)/98)+5/41*cos(23/25-(3506*t)/31)+6/41*cos(42/125-(3217*t)/32)+5/29*cos(23/33-(2463*t)/28)+3/35*cos(24/25-(1797*t)/22)+3/19*cos(5/22-(6258*t)/83)+2/19*cos(9/41-(1797*t)/26)+1/37*cos(106/47-(5215*t)/83)+165/68*cos(35/22-(377*t)/30)+247/32*cos((289*t)/46+148/57)+10/27*cos((377*t)/20+20/27)+29/48*cos((377*t)/15+34/15)+15/32*cos((377*t)/12+30/11)+13/29*cos((377*t)/10+35/18)+9/22*cos((2375*t)/54+31/21)+12/23*cos((1709*t)/34+12/11)+9/23*cos((1753*t)/31+47/24)+4/29*cos((7634*t)/81+133/43)+5/38*cos((2884*t)/27+317/136)+1/10*cos((2507*t)/21+20/17)+2/17*cos((2507*t)/19+39/34)+2/33*cos((5347*t)/37+28/31)+1/63*cos((3927*t)/25+59/49)+1/21*cos((5259*t)/31+49/44)+6/49*cos((2463*t)/14+97/34)+1/17*cos((6013*t)/33+39/32)+2/15*cos((17530*t)/93+31/10)+1/20*cos((3217*t)/16+42/17)+1/28*cos((7477*t)/35+85/32)+1/115*cos((8143*t)/36+25/21)+1/63*cos((5347*t)/23+69/28)+2/29*cos((5014*t)/21+119/60)+1/27*cos((5636*t)/23+85/31)+1/40*cos((12315*t)/49+25/32)+1/50*cos((4637*t)/18+94/63)+1/19*cos((5014*t)/19+41/32)+1/78*cos((4593*t)/17+46/21)+1/46*cos((10694*t)/37+41/19)+1/21*cos((8564*t)/29+102/37)+2719/31

print('L3: ', arc_length(x3,y3,50)

Reply via email to