a sequence of variables

12 views
Skip to first unread message

chu-ching huang

unread,
Feb 4, 2009, 10:12:54 AM2/4/09
to sympy
Hi,

Maybe this had been discussed:

how to define a sequence of variables (by symbols), {x_1,x_2,---,x_n}
in case n is also a variable?

Thanks

Friedrich Hagedorn

unread,
Feb 4, 2009, 10:27:30 AM2/4/09
to sy...@googlegroups.com

Do you want this:

In [1]: var('x_1 x_2 x_n')
Out[1]: (x_1, x_2, x_n)

In [2]: x_1 + x_2 + x_n
Out[2]: x_1 + x_2 + x_n


By,

Friedrich

Fabian Seoane

unread,
Feb 4, 2009, 11:27:36 AM2/4/09
to sy...@googlegroups.com

You can also use DeferredVector:
In [1]: a = DeferredVector('a')

In [2]: a[1] + a[2] + a[3] + a[4] + a[54653656]
Out[2]: a[1] + a[2] + a[3] + a[4] + a[54653656]

just that the class lacks documentation, see http://code.google.com/p/sympy/issues/detail?id=1268
 



By,

 Friedrich





--
Fabian, http://fseoane.net/blog/

chu-ching huang

unread,
Feb 5, 2009, 9:57:10 PM2/5/09
to sympy
Just rebuild sympy-git source and test the following:

from sympy import *
a=DeferredVector('a')
b=DeferredVector('b')
n=10
A=eye(11)
a=Matrix(1,n,lambda i,j: 'a%g' %j)
b=Matrix(1,n,lambda i,j: 'b%g' %j)
A[0,1:]=a
A[1:,0]=b.transpose()
A.det()

and it shows the right answer:

1 - a0*b0 - a1*b1 - a2*b2 - a3*b3 - a4*b4 - a5*b5 - a6*b6 - a7*b7 -
a8*b8 - a9*b9

Thanks all.

Another suggestion is about the sympy documentation. I don't know how
"sympy" manage the doc soruce and create the doc in html or pdf
format.

Then I try another way to make "interactive" document of sympy as
follows:

1. Use TeXmacs to import (or open) sympy doc ( $sympy/html/
tutorial.html#calculus );
2. Use embedding TeXmacs python session to run python code directly
within TeXmacs. TeXmacs will call python to run the code and show the
result. This part owns the interactive feature!
3. Moreover, TeXmacs supports flexible output formats, including pdf.

Any interesting, reference test TeXmacs file (tm format) and pdf file
from:

http://diffusion.cgu.edu.tw/ftp/TeXmacs/sympy_tut.tm (and
sympy_tut.pdf)

Hope this might have help.

cch

Ondrej Certik

unread,
Feb 7, 2009, 6:13:52 PM2/7/09
to sy...@googlegroups.com
On Thu, Feb 5, 2009 at 6:57 PM, chu-ching huang <cch...@mail.cgu.edu.tw> wrote:
>
> Just rebuild sympy-git source and test the following:
>
> from sympy import *
> a=DeferredVector('a')
> b=DeferredVector('b')
> n=10
> A=eye(11)
> a=Matrix(1,n,lambda i,j: 'a%g' %j)
> b=Matrix(1,n,lambda i,j: 'b%g' %j)
> A[0,1:]=a
> A[1:,0]=b.transpose()
> A.det()
>
> and it shows the right answer:
>
> 1 - a0*b0 - a1*b1 - a2*b2 - a3*b3 - a4*b4 - a5*b5 - a6*b6 - a7*b7 -
> a8*b8 - a9*b9
>
> Thanks all.
>
> Another suggestion is about the sympy documentation. I don't know how
> "sympy" manage the doc soruce and create the doc in html or pdf
> format.

We use sphinx -- but I think you meant that you *know* how we manage
documentation?

>
> Then I try another way to make "interactive" document of sympy as
> follows:
>
> 1. Use TeXmacs to import (or open) sympy doc ( $sympy/html/
> tutorial.html#calculus );
> 2. Use embedding TeXmacs python session to run python code directly
> within TeXmacs. TeXmacs will call python to run the code and show the
> result. This part owns the interactive feature!
> 3. Moreover, TeXmacs supports flexible output formats, including pdf.
>
> Any interesting, reference test TeXmacs file (tm format) and pdf file
> from:
>
> http://diffusion.cgu.edu.tw/ftp/TeXmacs/sympy_tut.tm (and
> sympy_tut.pdf)
>
> Hope this might have help.

Thanks for the information. Are you using the texmacs files from
data/TeXmacs/? (In our git version)
It may be useful too for you.

Ondrej

Reply all
Reply to author
Forward
0 new messages