곡선의 길이

545 days ago by namy0727

x = var('x') @interact def arclength(f=sqrt(x), Start = input_box(default = 0), End = input_box(default = 1), n=input_box(default=1)): pretty_print(html('$$y = %s$$'%latex(f))) func(x) = f a = RDF(Start) b = RDF(End) dx = (b-a)/n xpts = [a+i*dx for i in range(n+1)] ypts = [func(x=xpts[i]) for i in range(n+1)] p=Graphics() ds = [] for i in range(0,n): p+=line([(xpts[i],ypts[i]),(xpts[i+1],ypts[i+1])]) dx = xpts[i+1] - xpts[i] dy = ypts[i+1] - ypts[i] ds.append(sqrt(dx^2 + dy^2)) Ln = sum(ds); Ln = RDF(Ln) dydx = diff(f,x) L = integral(sqrt(1+dydx*dydx),x,a,b); L = RDF(L) err = abs(L - Ln) p+=plot(func(x),(x,a,b),color='red') p.show(aspect_ratio=1) print "L =", L print "Ln = %s" %(Ln) print "Error =", err 
       

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

t, x = var('t, x') a = 1; b = 3 dt = (b-a)/20; dt = RDF(dt) @interact def arclengthfunc(f = input_box(default = x^2 - (1/8)*log(x), label = 'f', type = SR), xpoint = slider(a,b,dt,default=a)): pretty_print(html('$f(x) = %s$'%latex(f))) func = f.subs(x=t) dydt = diff(func,t) dsdt = sqrt(1+dydt^2); dsdt.simplify_full() assume(x>a) s = integral(dsdt,t,a,x) pretty_print(html('$s(x) = %s$'%latex(s))) L = s(x=xpoint); L=RDF(L) pretty_print(html('$s(%s) = %s$'%(xpoint,L))) p = plot(func,(t,0,1))+plot(func,(t,1,3), color='red', aspect_ratio=1) p+= point((1,1), color='red', size=30) + point((xpoint,func(t=xpoint)), color='red', size=30) p.show() 
       

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