[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [femm] lua script data storage in vectors and matrices



ac090960 wrote:

Hello guys,
Inside a lua script I m not able to create/define a vector or matrix
in which store data coming from femm calculation i.e. Bx By and so on.
Are there any way or procedure to create vectors and matrices or
equivalent other method to store data like B, H, J ... coming from femm calculation using a lua command /language?


Any help and suggestion is welcome
Arnoldo

Check out section 11.3 in "Programming in Lua" at http://www.inf.puc-rio.br/~roberto/luabook1.pdf
Cribbing a bit from the book:


*
11.2 Matrices and multi-dimensional arrays

*There are two main ways to represent matrices in Lua. The first one is to use an array of arrays, that is, a table wherein each element is another table. For instance, you can create a matrix of zeros with dimensions N, M with the following code:

mt = {} -- create the matrix
for i=1,N do
mt[i] = {} -- create a new row
for j=1,M do
while j <= M do
mt[i][j] = 0
end
end

Because tables are objects in Lua, you have to explicitly create each row to create a matrix. At one hand, this is certainly more verbose than simply declaring a matrix, as you do in C or Pascal. On the other hand, that gives you more flexibility. For instance, you can create a diagonal matrix changing the line

for j=1,M do

in the previous example to

for j=i,M do

With that code, the diagonal matrix uses only half the memory of the original one.

The second way to represent a matrix in Lua is composing the two indices into a single one. If the two indices are integers, you can multiply the first one by a constant and then add with the second index. With this approach, our matrix of zeros with dimensions N, M would be created with

mt = {} -- create the matrix
for i=1,N do
for j=1,M do
mt[i*M+j] = 0
end
end



--
David Meeker
email: dmeeker@xxxxxxxx
www: http://femm.berlios.de/dmeeker