Reputation: 147
If I want to define a function f(n) that calculates the determinant of a n times n-matrix like the Vandermonde determinant containing n variables x1,...,xn what is a good way to define the variables as variables.
If I want to do it in advance, then I have to fix an arbitrary maximal number of n, if I do it inside the routine then they will be definied multiply.
Is there an elegant way to do say that x(i) should be a variable for all i?
Upvotes: 1
Views: 153
Reputation: 3348
Well, if you use the notation x || (1..10)
you will generate ten symbols named x1, ..., x10. Although I'm not quite sure this is actually what you want to do.
Another way is to define the matrix that using either a function or the symbol keyword. For example: Matrix(3, 3, (i, j) -> alpha[i]^(j-1))
creates a 3x3 Vandermonde matrix and Matrix(4, 4, symbol=a)
creates a 4x4 matrix with entries a[i, j]
.
I hope this helps.
Upvotes: 2