# Can I define an n-dimensional matrix?

I'm sure this is a basic question that has been asked before but I'm too stupid to find it.

What I'd like to do is something like this

k=var('n')
assume(n, 'integer')
assume(n>0)
VS = MatrixSpace(SR, n, 1)


to get the space of all n×1 matrices, i.e. column vectors. Is it at all possible to define a generalized n-dimensional vector or n×n matrix? Or am I just taking the completely wrong approach here?

Edit: Forgot to mention that the error I get is

ValueError: cannot convert n to int

edit retag close merge delete

Sort by » oldest newest most voted

There is no way to define a MatrixSpace without fixing the number of columns and rows. You can see this by looking into the code:

sage: MatrixSpace??
[...]
def __init__(self,...
[...]
nrows = int(nrows)
ncols = int(ncols)


Hence, Sage can not accept a symbolic variable n as the number of columns/rows.

A question remains : what do you want to ask to Sage about such a general matrix space where entries are not determined ? There maybe a workaround for a precise question.

more

Well, generally what I'd like to do is some linear algebra without specifying the number of dimensions but just getting results that are true for arbitrary *n*. Guess that was to general an answer? I figured out my current problems by hand but it'd still be nice to have a software that can do such things.

( 2013-06-16 19:43:51 +0200 )edit

I have the same issue. I want to compute an expression, similar to: sum{K_i * sen(alpha_i)} where i goes from 1 to n, being n also a variable.

( 2019-03-05 15:09:24 +0200 )edit