davidedc / Algebrite

Computer Algebra System in Javascript (Typescript)
http://algebrite.org
MIT License
966 stars 59 forks source link

dedicated helper functions to get/set a row/column of a matrix (2D tensor) #51

Open CesMak opened 7 years ago

CesMak commented 7 years ago

Hey There i wonder if its is possible to set and get a vector within a matrix with algebrite I just found getting an entry within a matrix with cofactor.....

what I want is something like: getRowVectorofMatrix(Matrix,Row) and the same for Columns a getter and a setter this would be a really nice feature for me.

Best Markus

davidedc commented 7 years ago

let's stick to 2D as you mention - get/set of a row is trivial, as matrixes are stored by rows. Get/Set of a column is less trivial. In the meantime we have a function, just transpose, get/set, then transpose again.

Jean-MarieL commented 6 years ago

Does not seems trivial to me at API level (how to set a matrix in JS ?) BTW I hope I am not too stupid but I cannot figure out why Algebrite.eval('[[1,2],[3,4]]').toString() gives me "[[-1,-2],[-3,-4]]" .ful CAS Many thanks for helping me with this wonderfull CAS

davidedc commented 6 years ago

Other points I didn't think about:

Jean-MarieL commented 6 years ago

Thanks, Davide, for your immediate reaction. I am eager to read from you again ! Bon courage pour tous vos développements. Jean-Marie

Le 25 juil. 2018 à 23:26, Davide Della Casa notifications@github.com a écrit :

No you are right it's not trivial. Matrixes are not stored "by rows", see below "elem" is a flat array of four elements, so it becomes a little cumbersome to get/set the right elements.

Algebrite.run('a = [[1,2],[3,4]]') "" Algebrite.eval("a").tensor.elem (4) [U, U, U, U] Plus there are other points I didn't think about:

setting a row/column should trigger a check so the number of elements in the row/column is correct getting a row/column: should we get a row/column by reference or by value? (to be checked what similar sw does). — You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/davidedc/Algebrite/issues/51#issuecomment-407901283, or mute the thread https://github.com/notifications/unsubscribe-auth/AH7HOE9WEWyJy6eWzmjiaI-di5TPcs6Tks5uKOKCgaJpZM4O-97m.

davidedc commented 6 years ago

Hi @Jean-MarieL sorry I got confused in a previous comment. Indeed matrices are stored by row, meaning:

a=[[1,2],[3,4]]
a[1]
> [1,2]
a[2] = [5,6]
a
> [[1,2],[5,6]]

so it should be easy to get/set a row.

As for why you'd get Algebrite.eval('[[1,2],[3,4]]').toString() gives me "[[-1,-2],[-3,-4]]" that's indeed very strange. If you keep getting that result please open another issue and we'll look into that further.