회전체 부피, 원통각법

565 days ago by namy0727

x = var('x') @interact def cylinder_vol(f = input_box(default = 2*x^2 - x^3, type = SR), Start = input_box(default = 0), End = input_box(default = 2), n=slider(4,100,4, default=16)): pretty_print(html('$$f(x) = %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)] midxs = [a+i*dx+dx/2 for i in range(n)] p=Graphics() dV = [] for i in range(0,n): dx = xpts[i+1] - xpts[i] yi = func(x=midxs[i]) p+=revolution_plot3d(yi,(x,xpts[i],xpts[i+1]), show_curve=True, opacity=0.5) dV.append(dx*2*pi*midxs[i]*yi) Vn = sum(dV); Vn = RDF(Vn) V = integral(2*pi*x*func,x,a,b); V = RDF(V) err = abs(V - Vn) p.show(aspect_ratio=[1,1,1]) print "V =", V print "Vn = %s" %(Vn) print "Error =", err 
       

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