Converting to decimal values from fractional values of terms of a sequence

asked 2017-10-14 08:19:52 -0600

anonymous user

Anonymous

updated 2017-10-14 08:21:33 -0600

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)

edit retag flag offensive close merge delete

Comments

  1. This smells "homework" at 15 feets...
  2. This is more a Python question.Look up "string formatting" and "string splicing" in Python documentation.
Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2017-10-14 19:25:58 -0600 )edit

To display inline code, use backticks. To display blocks of code or error messages, separate them by a blank line from the rest of the text, and indent them with 4 spaces, or select code lines and click the "code" button (the icon with '101 010').

For instance, typing

If we define `f` by

    def f(x, y):
        return (x, y)

then `f(2, 3)` returns `(2, 3)` but `f(2)` gives:

    TypeError: f() takes exactly 2 arguments (1 given)

will produce:

If we define f by

def f(x, y):
    return (x, y)

then f(2, 3) returns (2, 3) but f(2) gives:

TypeError: f() takes exactly 2 arguments (1 given)

Can you edit your question to do that?

slelievre gravatar imageslelievre ( 2017-10-15 02:04:13 -0600 )edit