# MAT 142 Days 11-14

## 1679 days ago by kcrisman

Here is the same interactive thing letting you test out approximations to arc length we tried in the written thoughts.  Convincing?

@interact def arc_length(f=input_box(x^3-x),a=-1,b=1,steps=slider(1,20,1,4)): f(x) = f real_value=sqrt(1+diff(f,x)^2).nintegral(x,a,b)[0] P=plot(f,x,a,b,thickness=1) Q=point((a,f(a)),rgbcolor='red',pointsize=5) est_value=0.0 dx=(b-a)/steps x0=a for m in range(steps): Q+=line([(x0,f(x0)),(x0+dx,f(x0+dx))],rgbcolor='red') est_value+=sqrt(dx^2+(f(x0)-f(x0+dx))^2).n() x0+=dx Q+=point((x0,f(x0)),rgbcolor='red',pointsize=5) html('<p>Actual arc length: $%s$</p>'%real_value) html('<p>Estimated arc length for $n=%s: %s$</p>'%(steps,est_value)) show(P+Q,xmin=a,xmax=b)

## Click to the left again to hide and once more to show the dynamic interactive window

Sadly, most arc length integrals can't be easily computed.  But we can usually do a good numerical approximation of them.  Here are two useful commands.

numerical_integral( sqrt(1+(cos(x))^2) ,0,pi)
 (3.8201977890277137, 4.2412715440006837e-14) (3.8201977890277137, 4.2412715440006837e-14)

Notice that this one:

• Does NOT include the variable, just the endpoints
• DOES give you both the approximation and a bound on the error.
n( integral( sqrt(1+(cos(x))^2) ,x,0,pi) )
 3.820197789027712 3.820197789027712

This one is the usual syntax, except I put everything inside of the "n" function, which does a "n"umerical approximation.  It uses a slightly different algorithm.

The following interact is sort of interesting.  It asks what the length of $x^n$ between $x=0$ and $x=1$ looks like as $n$ gets really big.

@interact def _(n=(3,[1..100])): P = plot(x^n,x,0,1) estimate = sqrt(1+(diff(x^n,x))^2).nintegral(x,0,1)[0] P.show(figsize=[3,3],aspect_ratio=1) html("The estimate of $\int_0^1 x^{%s}dx$ is \n$%s$"%(n,estimate))

## Click to the left again to hide and once more to show the dynamic interactive window

Of course, we also want to talk about arc length in parametric plots.  Here is how to do a parametric plot in Sage.

t = var('t') show(parametric_plot( (3*cos(t),sin(t)), (t, 0, 2*pi)),aspect_ratio=1)

Or, here is an interactive way to do it!  Be sure to do all your variables as $t$, though.

var('t') @interact def _(x=3*cos(t),y=sin(t),t_0=0,t_1=2*pi): x(t) = x y(t) = y show(parametric_plot( (x,y), (t, t_0, t_1)),aspect_ratio=1)

## Click to the left again to hide and once more to show the dynamic interactive window

This is the fact I mentioned about circles.

t = var('t') show(parametric_plot( ((1-t^2)/(t^2+1),(2*t)/(t^2+1)), -100, 100, plot_points=2000),aspect_ratio=1)

Here are the arc length of Lissajous curves.  So pretty.  Remember, click below and then click evaluate.

t = var('t') @interact def _(n=[1..10],m=[1..10]): value=numerical_integral(sqrt((-m*sin(m*t))^2+(n*cos(n*t))^2),0,2*pi)[0] P=parametric_plot((cos(m*t),sin(n*t)),(t,0,2*pi),rgbcolor=hue(.1*n+.01*m)) html("$(\cos(%st),\sin(%st))$"%(m,n)) html("$%s$ is about the total length of this curve!"%value) show(P,aspect_ratio=1)