Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - 3rik

Pages: 1 [2] 3 4 ... 8
16
TI-Nspire / Re: Matrix Library
« on: July 05, 2012, 08:33:41 pm »
I've finished all the basic stuff.

I'll attach it here and update the first post.

Edit:

The documentation is included in the source.

Here's some code to test the library out.
Code: [Select]
m = matrix.new({{2, 5, 7}, {5, 7}, [4] = {5, 6, 7, 3}})
print(m)
n = matrix.new({{2, false, "7"}, {true, 7}, {5, 6, 0, 3}, {}})
print(n)
o = m[1]
print(o[1], o[2], o[3], o[4], "\n")
print(o[2], m[1][2])
o[2] = 4
print(o[2], m[1][2])
m[1][2] = 5
print(o[2], m[1][2])
m[3] = {4, [3] = 5}
print(m)
print(tostring(-m))
p = m:copy()
print("\n", "\n", m, "\n", p, "\n", "\n")
print(m:isequal(p))
print(m + p == p:ebemult(3) - m)
print(p:ebemult(m:ebediv(5)))
print(m:totable())
print(unpack(m:totable()[1]))
print()
for row, col, val in p:mpairs() do
    print(row, col, val)
end
print()
m = m + 1
print(p*m)
print(m*p)
print(m:trans()*p)
print(m.dim[1], m.dim[2], m.dim.rows, m.dim.cols)
print(matrix.gen.zero(4)+m == m)
print(matrix.gen.random(5))
print(matrix.gen.random(5, 2))
print(matrix.gen.random(5, 2, 3))
print(matrix.gen.random(5, 2, 3, 10))
m = m:submatrix(2, 3, 2, 3) --now a 2 x 2
print(m)
m = matrix.insert.row(m, 2, {44, 6, 7}) --truncated
print(m)
m = matrix.insert.col(m, 2, {44, 6, 7, 8}) --truncated
print(m)
print(matrix.remove.row(m, 2))
print(m)
m = matrix.remove.row(select(1, matrix.remove.col(m, 1)))
print(m)

17
Math and Science / Re: Matrices/Complex Numbers
« on: July 02, 2012, 06:36:23 pm »
We can use a calculator for math too?? O.O

Or math can be used to make games.  ;)

18
Math and Science / Matrices
« on: July 01, 2012, 01:48:30 pm »
I'm at the point in programming where I need to program the LU decomposition, except I have no idea how to do that. I understand the basic concept of it; find lower and upper triangle matrices that produce the original matrix. However, since I haven't taken linear algebra yet, there are some parts that either I don't understand or I'm unfamiliar with their notation. Also, there are references to diagonal and pivot matrices. Which method is most useful in applications. I would also like a method that works for the most matrices possible. Any help would be appreciated.

19
TI-Nspire / Re: Matrix Library
« on: June 23, 2012, 04:50:53 pm »
Yeah this type of thing would work and it would be far easier to manage. I think in the long run it will probably be shorter and faster to do some thing like this, rather than basically making a new type out of an old one.
Thanks.

20
TI-Nspire / Re: Matrix Library
« on: June 23, 2012, 04:39:01 pm »
I was considering that. If this is too much to manage, I'll probably just switch to that plan.

21
TI-Nspire / Re: Matrix Library
« on: June 23, 2012, 04:30:20 pm »
I think this is getting closer to what I came up with. It's just that my code is so inflated.
btw thanks for all the help you're offering.  :)

22
TI-Nspire / Re: Matrix Library
« on: June 23, 2012, 04:20:29 pm »
One issue with this kind of matrix is that it allows a whole row to be assigned at one time without being checked if all the values are numbers or nils. I also want to still be able to assign to the matrix, just not directly. Also I would like to make all zeros be nils in the matrix. It allows large spaece matrices to be stored without taking up a massive amount of space.
Code: [Select]
a = matrix.new({[10000] = { [100000] = 8}})
a[2][3] = 6
print(a[2][3]+a[250][44]+a[10000][100000]) --prints 14

23
TI-Nspire / Re: Matrix Library
« on: June 23, 2012, 01:15:00 pm »
It's just that the matrix is a bunch of tables inside a table. Since the tables are passed by reference they could be altered using class(). Another tricky part is that when assigning to a spot in the matrix like
Code: [Select]
A[1][2] = 6
the A[1] is found by __index not __newindex so it is like
Code: [Select]
B = A[1]
B[2] = 6
--or
(A[1])[2] = 6
the reference to A[1] is assigned to B and then B[2] is assigned 6. This means __index and __newindex have to work together to allow assignment but control what can be assigned where while protecting the reference to the actual data.

24
TI-Nspire / Re: Matrix Library
« on: June 23, 2012, 12:35:00 pm »
It's just that I don't want the data to be directly accessible to the programmer. I also want zeros to be stored as nils but when they're indexed, they return a 0. This is my version. It's still a work in progress.

I'm having issues with [ key ] turning into [nobbc] so I attached the file instead.

25
TI-Nspire / Re: Matrix Library
« on: June 22, 2012, 09:30:40 pm »
here is an example of what I was trying to say:
Code: [Select]
matrix = {}
matrix.new = function(data)
local mat={}
setmetatable(mat, {__index = function(tbl, nobbc)
return data[nobbc]
end
})
return mat
end
matrix1 = matrix.new({{4}})
matrix2 = matrix.new({{7}})
print(matrix1[1][1], matrix2[1][1], mat, data) --prints 4 7 nil nil
nobbc was supposed to be key but I was having issues

This is an insecure example, but it works

26
TI-Nspire / Re: Matrix Library
« on: June 22, 2012, 08:46:26 pm »
matrix1 = {{1, 2, 3}, {4, 5, 6}, ["add"]=function(self, m2) end}
what about
Code: [Select]
setmetatable(matrix1, {__index=matrix})?
I think it can be done but I'm just not sure how to organize it.

27
TI-Nspire / Matrix Library
« on: June 22, 2012, 06:28:21 pm »
As the title implies, I'm planning on making a matrix library for Lua. I want it to be usable in computer Lua, too, so I don't want to use math.eval or other calculator dependent functions in this library. The math related aspect of this project can be found here.

Spoiler For fixed (I think):
My first roadblock is with being able to make the matrix itself.

I want the matrix to be unable to be edited without using the matrix functions. This can be accomplished using up-values, __index, and __newindex but I cant seem to figure out a good way to do this. I also want all the matrix functions to be available from the matrix.

Basically, I want it to be tamper-proof. I imagine it functioning like like this: (don't worry about the functions them selves)

Code: [Select]
matrix1 = matrix.new({{2, 3, 4}, {3, 4, 5}})
matrix2 = matrix.new({{1, 0, 5}, {2, 5, 9}})

matrix1:add(matrix2) == matrix.add(matrix1, matrix2) --true

matrix1[1] = {2} --error

matrix1[1][1] = 2 --no error

matrix1[1][1] = "2" --converts to number

matrix1[1][1] = true --error

table.maxn(matrix1) == 0 --true matrix1 doesn't actually contain any values, it forwards them to a local table in the matrix.new function

matrix1[1][300] = 2 --error wrong dimensions

If anyone has any suggestions, it would be very helpful.

Edit: I've attached a copy to the first post so people don't have to search through the topic for a copy.



Lua Matrix Library
Last Update: July 16, 2012, 03:03:56 pm
Version: 0.9.2
New Features: added lu, trace, det, ref, rref, and rank


28
Math and Science / Re: Matrices/Complex Numbers
« on: June 15, 2012, 01:45:53 pm »
Wow! rref is useful! :D I'll add that to my list for sure.

Right now I just need to sort through all the matrices stuff on the internet, so any help sorting out the things that are helpful and the things that take up space. I'll worry about how I'll do things later. I only need a list of things that are possible right now.

29
Math and Science / Re: Matrices/Complex Numbers
« on: June 15, 2012, 09:26:26 am »
dividing matrices doesn't really exist..
I'm aware that it isn't formally defined. A secondary goal of this library is to provide some abstraction for somewhat large amounts of data. It falls under more of the applied math side of the spectrum rather than pure math. The pseudoinverse would work fine for the operation you're talking about. (The element-by-element division would have a different result as multiplying by the inverse/pseudoinverse)

your equality should be more advanced. rows are multiplications with a scalar, then they're equal too
I'm a bit confused about this one. I'm pretty sure I've seen definitions where the dimensions must be the same and each pair of corresponding elements must be equal for the matrices to be equal. I could add something that checks if the matrices are proportional if that's what you meant.

check if they're consistent by solving them
I'm not really sure I understand this one.

(row) reduced echelon form could come in handy, this can be done with math.eval i think (but i really don't know what or how it will return then)
A = L*U
A = Q*R
I don't know what these are, but I'll look into it.

determinant
I have this one already under One Matrix Operations and Properties

adding a scalar to a matrix doesn't work either. You have to add the scalar*identinty
^this for substraction
I know in pure math you would have to do that. It's more for convenience. If someone were keeping track of a bunch of data and wanted to shift them all by a constant, they could use this as a shortcut. (It's just a faster way of your method, even if it is technically wrong mathematically). Would it be better to describe it as a shift? The TI-84+ allows it while the nspire doesn't.

checking for inversability (this can be done in like 25 ways or something, so it should be possible xp )
This would be available with the determinant. It might look like
Code: [Select]
matrix.det(matrixname)~=0 --same as isinvertable(matrixname)
Thanks a lot for this feedback. :D I'm just gathering some ideas right now, so if you have more ideas I'd love to hear them. There's just too much information out there.

30
Math and Science / Re: Matrices/Complex Numbers
« on: June 14, 2012, 11:07:47 pm »
Thanks for pointing out that confusion. I reorganized the categories so that it might be less confusing.

Pages: 1 [2] 3 4 ... 8