Ask Your Question
0

How do we graph sequences

asked 2017-08-11 19:00:24 +0100

Ellis Shamash gravatar image

For example def agen(max=Infinity): n = 1 an = 1 while n <= max: yield an n += 1 an = (an + 1)/an^2

a = agen(10) for i in a: print i.n() The above print the sequence, but how do I graph it.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2017-08-12 09:43:28 +0100

vdelecroix gravatar image

Simpler

A = [(-1)^n/n for n in range(1,20)]
list_plot(A)
edit flag offensive delete link more

Comments

Thank you very much.

Ellis Shamash gravatar imageEllis Shamash ( 2017-08-14 00:47:58 +0100 )edit
0

answered 2017-08-12 05:36:55 +0100

fidbc gravatar image

updated 2017-08-12 05:43:56 +0100

tl; dr

point2d(enumerate(agen(10),1))

Here is one possibility. Suppose A contains the terms of the sequence and we assume they are labelled starting at 1.

A = [(-1)^n/n for n in range(1,20)]
pts = [(i,ai) for i,ai in enumerate(A,1)]
point2d(pts)

The idea is to construct a list of points that consists of ordered pairs $(i,a_{i})$ to be sent as an argument to point2d.

In your case you may be able to construct A as follows:

A = [ai for ai in agen(10)]

Perhaps you could skip that part and directly construct the list of points:

pts = [(i,ai) for i,ai in enumerate(agen(10),1)]

If we are confident enough, then we may just skip all steps and arrive at:

point2d(enumerate(agen(10),1))
edit flag offensive delete link more

Comments

Thank you very much.

Ellis Shamash gravatar imageEllis Shamash ( 2017-08-14 00:56:53 +0100 )edit

Feel free to upvote/accept answers if you found them useful.

fidbc gravatar imagefidbc ( 2017-08-14 03:03:30 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-08-11 19:00:24 +0100

Seen: 618 times

Last updated: Aug 12 '17