Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Converting to decimal sequence values from fractional values

I had tried this code. Please give some code so that the sequence values can be converted to its corresponding decimal values

var('n k')

f(n)=(-3*n)+(5/n)+(4/n^2)+(1/n^3)+2

start=2

@interact()

def _(n=slider(start,30,1,8)):

print "i\tterm\tpartial sum"

print "-------------------------------------"

for i in srange(start,n+1,1):

print i,"\t",f(i),"\t",sum(f(k),k,start,i).N(digits=20)

p1 = plot(f(x), (x, start, n), color="red", fill=True)

p2 = list_plot([(i,f(i)) for i in range(start, n, 1)], color="blue")

p3 = add( [ polygon2d( [[i-.5,0],[i-.5,f(i)],[i+.5,f(i)],[i+.5,0]], alpha=.2, color="green") for i in range(start,n)])

show(p1+p2+p3,aspect_ratio=n/2)

Converting to decimal sequence values from fractional values

I had tried this code. Please give some code so that the sequence values can be converted to its corresponding decimal values

var('n k')

f(n)=(-3*n)+(5/n)+(4/n^2)+(1/n^3)+2

start=2

@interact()

def _(n=slider(start,30,1,8)):

print "i\tterm\tpartial sum"

print "-------------------------------------"

for i in srange(start,n+1,1):

print i,"\t",f(i),"\t",sum(f(k),k,start,i).N(digits=20)

p1 = plot(f(x), (x, start, n), color="red", fill=True)

p2 = list_plot([(i,f(i)) for i in range(start, n, 1)], color="blue")

p3 = add( [ polygon2d( [[i-.5,0],[i-.5,f(i)],[i+.5,f(i)],[i+.5,0]], alpha=.2, color="green") for i in range(start,n)])

show(p1+p2+p3,aspect_ratio=n/2)