Welcome Guest! To enable all features please Login. New Registrations are disabled.

Notification

Icon
Error

Login


Options
Go to last post Go to first unread
Offline Infinity  
#1 Posted : 19 June 2012 20:38:11(UTC)
Infinity


Rank: Member

Groups: Registered
Joined: 19/01/2012(UTC)
Posts: 12
Man

Was thanked: 3 time(s) in 2 post(s)
Hello,

I found a bug when accessing not assigned positions within a matrix.
In the following example I assigned on variable 'a' a matrix with two rows and one column.
Now when I access not assigned rows or columns I also get values back.
See my example below:
SMath Version 0.95

Example Matrices Bug

Best Regards,
Infinity

Wanna join the discussion?! Login to your SMath Studio Forum forum account. New Registrations are disabled.

Offline omorr  
#2 Posted : 19 June 2012 21:27:11(UTC)
omorr


Rank: Administration

Groups: Registered, Advanced Member
Joined: 23/06/2009(UTC)
Posts: 1,740
Man
Serbia

Was thanked: 318 time(s) in 268 post(s)
Hello Infinity,

I suppose it has something with internal representation of matrix with mat() function:
marix size

Hmm...I am not sure if it could be accepted as a feature or a bug Unsure
I prefer this to be regarded as a bug.

Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
Offline Andrey Ivashov  
#3 Posted : 21 June 2012 01:12:40(UTC)
Andrey Ivashov


Rank: Administration

Groups: Developers, Registered, Knovel Developers, Administrators, Advanced Member
Joined: 11/07/2008(UTC)
Posts: 1,616
Man
Russian Federation

Was thanked: 1978 time(s) in 666 post(s)
Yep, it's a bug. Will fix.

Thank you and regards.
thanks 1 user thanked Andrey Ivashov for this useful post.
on 21/06/2012(UTC)
Offline Stuart Bruff  
#4 Posted : 21 June 2012 02:06:29(UTC)
Stuart Bruff

Rank: Newbie

Groups: Registered
Joined: 16/06/2012(UTC)
Posts: 7
United Kingdom
Location: Home Counties

Originally Posted by: smath Go to Quoted Post
Yep, it's a bug. Will fix.

Thank you and regards.


However, ... what would be nice is if, in Matlab style, a single index could point into a 2D matrix



(ie, the first index in this case would not be needed) ... except I'd prefer it if the indexing took place in column order rather than row order. Smile

Stuart

M:mat(1,4,7,2,5,8,3,6,9,3,3)

v:line(for(k,range(1,rows(M)*cols(M)),el(v,k):el(M,1,k)),v,2,1)

transpose(v)=mat(1,4,7,2,5,8,3,6,9,1,9)

... sorry, that first MATH line is supposed to be a 3x3 matrix and the second MATH line is supposed to be showing a program: v:line(for(k,range(1,rows(M)*cols(M)),el(v,k):el(M,1,k)),v,2,1)

for(k,range(1,rows(M)*cols(M)),el(v,k):el(M,1,k))

Edited by user 21 June 2012 02:19:49(UTC)  | Reason: doesn't display what I intended

Offline omorr  
#5 Posted : 21 June 2012 09:44:30(UTC)
omorr


Rank: Administration

Groups: Registered, Advanced Member
Joined: 23/06/2009(UTC)
Posts: 1,740
Man
Serbia

Was thanked: 318 time(s) in 268 post(s)
Hello,

It crossed my mind that stack(1) and augment(1) might be made to be used with a single argument - matrix with more than one row and one column - in that way that stack(M) will make a column vector by placing matrix columns one below the other and augment() will make a row vector by placing matrix rows next to each other.

Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
Offline Davide Carpi  
#6 Posted : 21 June 2012 10:21:15(UTC)
Davide Carpi


Rank: Advanced Member

Groups: Registered, Advanced Member
Joined: 13/01/2012(UTC)
Posts: 2,647
Man
Italy
Location: Italy

Was thanked: 1329 time(s) in 875 post(s)
Hi Good

an alternative way to transform a matrix in a vector, whitout loops (could be useful for large matrices, I think)

mat2vector snippet

here is the file in the image: mat2vector.zip


regards,

w3b5urf3r
If you like my plugins consider to support SMath Studio buying a plan; to offer me a coffee: paypal.me/dcprojects
thanks 1 user thanked Davide Carpi for this useful post.
on 21/06/2012(UTC)
Offline Andrey Ivashov  
#7 Posted : 24 June 2012 19:19:24(UTC)
Andrey Ivashov


Rank: Administration

Groups: Developers, Registered, Knovel Developers, Administrators, Advanced Member
Joined: 11/07/2008(UTC)
Posts: 1,616
Man
Russian Federation

Was thanked: 1978 time(s) in 666 post(s)
Fixed, with improvement:

Originally Posted by: Stuart Bruff Go to Quoted Post
However, ... what would be nice is if, in Matlab style, a single index could point into a 2D matrix



(ie, the first index in this case would not be needed) ... except I'd prefer it if the indexing took place in column order rather than row order. Smile


Regards.
thanks 1 user thanked Andrey Ivashov for this useful post.
on 24/06/2012(UTC)
Offline mkraska  
#8 Posted : 24 June 2012 23:09:00(UTC)
mkraska


Rank: Advanced Member

Groups: Registered
Joined: 15/04/2012(UTC)
Posts: 1,986
Germany

Was thanked: 1124 time(s) in 721 post(s)
I guess that indexing order (row or column) is a matter of taste. As I understand Andrey's post, the default order is going to be changed from row order in 0.95 to column order.

This is what 0.95 does:

M:mat(1,4,7,2,5,8,3,6,9,3,3)

for(i,range(1,rows(M)*cols(M)),el(v,i):el(M,1,i))

transpose(v)=mat(1,4,7,2,5,8,3,6,9,1,9)

Accessing the transpose should provide column ordering:

for(i,range(1,rows(M)*cols(M)),el(v,i):el(transpose(M),1,i))

However, the result is a complaint, that the requested element does not exist.

If the matrix is transposed in advance, the trick works:

M:transpose(M)

for(i,range(1,rows(M)*cols(M)),el(v,i):el(M,1,i))

transpose(v)=mat(1,2,3,4,5,6,7,8,9,1,9)

Also, use of eval works.

for(i,range(1,rows(M)*cols(M)),el(v,i):el(eval(transpose(M)),1,i))

I don't have an idea, how to explain these differences.

Slightly off topic: IMHO linear indexing in general does not contribute to the readability of algorithms (the reader must make assumptions on row or column ordering). In contrast to this I would highly welcome another matlab feature: impicit iteration over vector valued indices.

They would be a highly welcome equivalent to Mathcad range variables and are consistent to the usual math notation.

Best regards, Martin Kraska

Edited by user 24 June 2012 23:11:44(UTC)  | Reason: Not specified

Martin Kraska

Pre-configured portable distribution of SMath Studio: https://smath.com/wiki/SMath_with_Plugins.ashx
thanks 1 user thanked mkraska for this useful post.
on 25/06/2012(UTC)
Offline Stuart Bruff  
#9 Posted : 25 June 2012 00:44:54(UTC)
Stuart Bruff

Rank: Newbie

Groups: Registered
Joined: 16/06/2012(UTC)
Posts: 7
United Kingdom
Location: Home Counties

Originally Posted by: mkraska Go to Quoted Post
I guess that indexing order (row or column) is a matter of taste.
Yes.

Quote:
As I understand Andrey's post, the default order is going to be changed from row order in 0.95 to column order.
That is my understanding too.

Quote:
...IMHO linear indexing in general does not contribute to the readability of algorithms (the reader must make assumptions on row or column ordering).
Although the reader may not be able to implicitly determine the element order for a single index into an array, this is, I believe, one of those cases where the application's rules determine the interpretation, as in Matlab. The ability to use a single index is potentially useful for multi-dimensional array (MDA) indexing (where the number of dimensions can be arbitrarily large).

Quote:
In contrast to this I would highly welcome another matlab feature: impicit iteration over vector valued indices.

They would be a highly welcome equivalent to Mathcad range variables and are consistent to the usual math notation.
The whole topic of array handling is probably worthy of separate discussion, covering, for example, indexing of multi-dimensional arrays, nested arrays and tensors.

... if such things as MDAs and tensors are for the distant future, then I propose that the provision of IsArray, IsScalar and IsFunction functions would be immediately useful for manipulating nested arrays and a more direct indexing for nested arrays would be beneficial, eg nested indexing on left hand side of an assignment or el having as many arguments as are necessary to index an arbitrarily deep nested array.



Stuart



Offline Stuart Bruff  
#10 Posted : 25 June 2012 08:48:45(UTC)
Stuart Bruff

Rank: Newbie

Groups: Registered
Joined: 16/06/2012(UTC)
Posts: 7
United Kingdom
Location: Home Counties

Originally Posted by: smath Go to Quoted Post
Fixed, with improvement:.


I just played with the update and I see that a single-index returns the results in row order.

A note from one of the Wiki tutorials:
"It is important to indicate that even though you can form row vectors, many of the matrix and vector functions defined in SMath Studio apply only to column vectors. Thus, column vectors are considered true vectors for the purpose of matrix operations in SMath"

If one creates a vector by use of a single indexing then the result is a column vector. So, for a 3x3 array my expectation would be that, dropping the second (column) index would be equivalent to retaining the first (row) index and that M<sub>2</sub> would return M<sub>2,1</sub> rather than M<sub>1,2</sub>. There is a lot of Matlab and Mathcad code out there that could be mapped to SMath and it would seem to make sense to use an indexing order that requires less modification to get it to run under SMath.

Just a thought, before the feature gets into regular use ...

Stuart
Offline mkraska  
#11 Posted : 25 June 2012 09:23:55(UTC)
mkraska


Rank: Advanced Member

Groups: Registered
Joined: 15/04/2012(UTC)
Posts: 1,986
Germany

Was thanked: 1124 time(s) in 721 post(s)
Hello,

here are my observations with build 4559. Highlighting is done for what I think is inconsistent.


  • linear indexing using just index values beyond the limits is now suppressed ("Requested matrix element does not exist" ):

    el(mat(1,2,3,4,5,6,7,8,9,3,3),1,5)=#@#

  • linear indexing using a single index works as announced, uses row ordering:

    el(mat(1,2,3,4,5,6,7,8,9,3,3),4)=4@#

  • linear indexing beyond the number of elements is now suppressed. The error message "Argument doesn't match to expected kind" is wrong. Should be "Requested matrix element does not exist"

    el(mat(1,2,3,4,5,6,7,8,9,3,3),10)=#@#

  • linear indexing does not work with matrix-valued functions (like transpose, inverse, etc), unless they are "eval"uated. Message "Argument doesn't match to expected kind"

    el(transpose(mat(1,2,3,4,5,6,7,8,9,3,3)),7)=#@#

  • column ordering is achieved by the following slightly cumbersome expression

    el(eval(transpose(mat(1,2,3,4,5,6,7,8,9,3,3))),7)=3@#

  • Nested el work (but do not try to transpose any of the sub-matrices)

    el(el(el(mat(1,2,3,4,mat(1,2,3,4,5,6,7,8,mat(1,2,3,4,5,6,7,8,9,3,3),3,3),6,7,8,9,3,3),5),3,3),7)=7@#


I would expect el(1), i.e. linear indexing, to work on any matrix valued function. Currently, it seems to work for expressions of type mat() and el(). el(2) has no problems with matrix valued functions:

el(el(el(mat(1,2,3,4,mat(1,2,3,4,5,6,7,8,transpose(mat(1,2,3,4,5,6,7,8,9,3,3)),3,3),6,7,8,9,3,3),5),3,3),1,2)=4@#

Best regards, Martin
Martin Kraska

Pre-configured portable distribution of SMath Studio: https://smath.com/wiki/SMath_with_Plugins.ashx
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.