Ask Your Question
1

Series and Sequences (Sage x Mathematica)

asked 2015-02-03 04:50:47 +0100

LRM gravatar image

updated 2015-02-03 11:32:46 +0100

vdelecroix gravatar image

Hello, all.

I am trying to move from Mathematica to Sage Math but I'm facing basic issues. I had read the manual and searched for the answer in many results from google and found no answer to things like this:

In Mathematica, if I want to generate a sequence of integers I do the following (just an example):

Table[4*n^2 + 3, {n, 0, 50}]  **or** Array[4 #^2 + 3 &, 44, 0]

and it will output the following:

{3, 7, 19, 39, 67, 103, 147, 199, 259, 327, 403, 487, 579, 679, 787, 903, 1027, 1159, 1299, 1447, 1603, 1767, 1939, 2119, 2307, 2503, 2707, 2919, 3139, 3367, 3603, 3847, 4099, 4359, 4627, 4903, 5187, 5479, 5779, 6087, 6403, 6727, 7059, 7399}

I saw the command range() but it doesn't accept a formula. Also, there is a mix of commands between Maxima and Python ... I'm really lost.

How can I generate the same list using Sage?

Thank you.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-02-03 04:56:59 +0100

LRM gravatar image

I found my own answer based on a related question, here is how I can do the same:

[(n,4*n^2 + 3) for n in range(51)]

Maybe I can find more ways to generate such sequences, maybe using lambda / "pure functions"

edit flag offensive delete link more

Comments

List comprehension as you did is the most common way. But as you wrote it, the output is a list of pairs and not {3, 7, ..., }. There is also the possibility of using: filter(lambda n: 4*n^2+3, range(51)) which I found less useful.

vdelecroix gravatar imagevdelecroix ( 2015-02-03 11:34:49 +0100 )edit
1

Yes, many such things are automatically available in Python, which is a powerful general-purpose programming language. You may also find the table command quite useful - just type table? and read the documentation for it.

kcrisman gravatar imagekcrisman ( 2015-02-03 15:17:58 +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: 2015-02-03 04:50:47 +0100

Seen: 1,300 times

Last updated: Feb 03 '15