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.
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.
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.
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
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.
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.
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
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)
Wow! rref is useful! 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.
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.
(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.
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.
matrix.det(matrixname)~=0 --same as isinvertable(matrixname) Thanks a lot for this feedback. 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.