16.01.2015 Views

Arc length

Arc length

Arc length

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

2/20/13 <strong>Arc</strong> <strong>length</strong> -- Sage<br />

<strong>Arc</strong> <strong>length</strong><br />

@interact<br />

def _(Function = sin(x), a = 0,b = pi, n=4):<br />

f(x)=Function<br />

dx = ((b-a)/n)<br />

k=var('k')<br />

m(k) = (f(a+k*dx) - f(a + (k-1)*dx))/dx<br />

S= dx*sum([sqrt(1+(m(k))^2) for k in [1..n]])<br />

html('<strong>Arc</strong> <strong>length</strong> approximation: $%s$' %N(S))<br />

g=diff(f,x)<br />

html('Exact arc <strong>length</strong>: $%s$'<br />

%numerical_integral(sqrt(1+g(x)^2),a,b)[0])<br />

#show(N(integral(sqrt(1+g(x)^2),(x,a,b))))<br />

p = plot( f(x), (x, a, b), color='green')<br />

#the old way that was less efficient<br />

#show(p+ sum(plot(f(a+k*dx)+m(k)*(x-(a+k*dx)), (x, a+(k-<br />

1)*dx, a+k*dx ), figsize=4 ) for k in [1..n]))<br />

q = line([(a+k*dx, f(a+k*dx)) for k in [0..n]])<br />

show(p+q, figsize = 4)<br />

Function sin(x)<br />

a 0<br />

b pi<br />

n 4<br />

<strong>Arc</strong> <strong>length</strong> approximation:<br />

Exact arc <strong>length</strong>:<br />

3.79009130853072<br />

3.82019778903<br />

test.sagenb.org/home/Carlos_Rodriguez/21/print 1/2


2/20/13 <strong>Arc</strong> <strong>length</strong> -- Sage<br />

test.sagenb.org/home/Carlos_Rodriguez/21/print 2/2

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!