Extracting matrix from a matrix

Extracting matrix from a matrix - Extract a matrix from an existing matrix - "slicing" - Messages

#1 Posted: 9/8/2016 5:27:29 AM
Radovan Omorjan

Radovan Omorjan

325 likes in 2052 posts.

Group: Moderator

I do not believe such a feature would ever exits in SMath (it does not exit in Mathcad, Prime etc. as well) but I just had an urge to mention this (again). Actually, after such a long time I had to believe it is impossible to just make it real because it would have been made already. For example, if any of you have some time, just read the post from a Guest about 6 years ago (here)

This is very common in other math packages - to extract a matrix from a matrix by having vector indexes. See the picture,

submatrixaugmentstack.png

it is clear what we want, but there is an error message. Of course, we can do this by using submatrix(), augment(), stack() function, or by for loop - but it can be sometimes a night mare.

Regards,
Ra
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
3 users liked this post
Davide Carpi 9/8/2016 7:45:00 AM, Serg 9/8/2016 8:05:00 AM, Andrey Ivashov 9/8/2016 10:27:00 AM
#2 Posted: 9/8/2016 7:45:48 AM
Davide Carpi

Davide Carpi

1415 likes in 2872 posts.

Group: Moderator

Very nice Radovan

something like this?

el_plus.sm (19 KiB) downloaded 263 time(s).
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
3 users liked this post
Serg 9/8/2016 8:05:00 AM, Radovan Omorjan 9/8/2016 9:45:00 AM, Martin Kraska 9/8/2016 9:27:00 AM
#3 Posted: 9/8/2016 9:38:41 AM
Martin Kraska

Martin Kraska

1222 likes in 2150 posts.

Group: Moderator

Wrote


something like this?



Yes, that would be something like vector valued indices in matlab. I support this proposal.

This would be the little brother of Mathcad range variables (implicit iteration in assignments over vector valued indices, currently this requires for loops)

The availability of range variables mitigates the need for el_plus in Mathcad, because you can define your index vectors r and c, create range variables

i=1...length(r), j=1..length(c)

Result[(i,j) = M[(r[i,c[j)



Martin Kraska Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
1 users liked this post
Radovan Omorjan 9/8/2016 10:22:00 AM
#4 Posted: 9/8/2016 10:21:03 AM
Radovan Omorjan

Radovan Omorjan

325 likes in 2052 posts.

Group: Moderator

Wrote

Very nice Radovan

something like this?

el_plus.sm (19 KiB) downloaded 263 time(s).



Just like that, very nice Davide . If you could make operators from these functions like el(M, that would be amazing

Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#5 Posted: 9/8/2016 10:26:13 AM
Andrey Ivashov

Andrey Ivashov

2269 likes in 3729 posts.

Group: Super Administrator

Implemented (will be available in new build).

submatrix_via_el_1.png

Thank you, Radovan.
5 users liked this post
Вячеслав Мезенцев 9/8/2016 1:48:00 PM, Radovan Omorjan 9/8/2016 10:35:00 AM, Serg 9/8/2016 10:48:00 AM, Martin Kraska 9/8/2016 11:08:00 AM, Davide Carpi 9/8/2016 12:28:00 PM
#6 Posted: 9/8/2016 10:31:46 AM
Radovan Omorjan

Radovan Omorjan

325 likes in 2052 posts.

Group: Moderator

Wrote

Wrote


something like this?



Yes, that would be something like vector valued indices in matlab. I support this proposal....



Exactly Martin, not just in Matlab but just in many other software where this kind of vector valued indices is a rather common (and an elegant) feature.

Regards,
Radovan

When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#7 Posted: 9/8/2016 10:37:51 AM
Radovan Omorjan

Radovan Omorjan

325 likes in 2052 posts.

Group: Moderator

Wrote

Implemented (will be available in new build).



You are very welcome Andrey, and I am really surprised about this very fast reaction of yours

I really do not know why this was not implemented earlier, and that is why I thought it was not possible.

I am glad that I was wrong

BTW, I consider this as a rather important feature.

Best Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#8 Posted: 9/8/2016 11:21:33 AM
Martin Kraska

Martin Kraska

1222 likes in 2150 posts.

Group: Moderator

Wrote

Implemented (will be available in new build).



Great. I assume that the feature isn't limited to range()-generated index vectors but can use arbitrary integer vectors.

Might be useful to have some shorthand for using all elements in a given dimension, perhaps an empty placeholder or "all" would do.

This would make the examples even more compact without adding problems for the reader.

Martin Kraska Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
#9 Posted: 9/8/2016 12:00:02 PM
Andrey Ivashov

Andrey Ivashov

2269 likes in 3729 posts.

Group: Super Administrator

Wrote

I assume that the feature isn't limited to range()-generated index vectors but can use arbitrary integer vectors.


I did afraid someone may ask this question. Yes, I didn't introduce any limits there, you can even use matrices:

submatrix_via_el_3.png

Not sure what it means, but it works

He-he...

submatrix_via_el_4.png
4 users liked this post
Davide Carpi 9/8/2016 12:28:00 PM, NDTM Amarasekera 9/8/2016 12:31:00 PM, Radovan Omorjan 9/8/2016 12:34:00 PM, sergio 9/8/2016 12:23:00 PM
#10 Posted: 9/8/2016 1:18:29 PM
Radovan Omorjan

Radovan Omorjan

325 likes in 2052 posts.

Group: Moderator

This would be very appreciated and would give some new opportunities (and unexpected behavior).

Moreover, my greedy mind does not let me go and bothers me with vector (matrix) indices for undefined variables. Here is the picture

symvecmat.PNG

I hope I made my point. The primer goal is to define a symbolic vector or matrix by this shorthand notation

Regards,
Ra
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#11 Posted: 9/8/2016 1:42:17 PM
Andrey Ivashov

Andrey Ivashov

2269 likes in 3729 posts.

Group: Super Administrator

submatrix_via_el_5.png
1 users liked this post
Radovan Omorjan 9/8/2016 1:54:00 PM
#12 Posted: 9/8/2016 1:50:23 PM
Andrey Ivashov

Andrey Ivashov

2269 likes in 3729 posts.

Group: Super Administrator

You can test new functionality in SMath Studio in the Cloud.

Here is my sandbox to play: http://smath.info/cloud/worksheet/gYFgZBnd.

Best regards, Andrey Ivashov.
1 users liked this post
Radovan Omorjan 9/8/2016 1:56:00 PM
#13 Posted: 9/8/2016 2:07:38 PM
Martin Kraska

Martin Kraska

1222 likes in 2150 posts.

Group: Moderator

If we could use the array valued indices on the left hand side of assignments, this would be close to having range variables like in Mathcad.

SS-14 could be closed.


Martin Kraska Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
1 users liked this post
Radovan Omorjan 9/8/2016 2:32:00 PM
#14 Posted: 9/8/2016 2:19:18 PM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

Sorry for "Mathcaders Primes", Mathcad 11 did it simple because
it supported index [indices] as argment. Smath does not.
Though submatrix look alike between Smath/Mathcad, except for
the indexing, they are not the same ...
Explain: In Mathcad, if you want to mirror a matrix [think of
an image], you just need to reverse the cols order. Smath does
not support the reverse cols order.

If you think others do something useful: YES, but useless for
practical Engineering works involving specific search in matrix
unless the software has been designed for.

When working with matrices [Smath, Mathcad ...] you need a
"Matrix Treasury" of utilities. You will have more than expected
in the attached document.

Thanks Radovan, most interesting subject.

Jean

Forum ForLoopList.gif

Utilities Matrix RemToDo [select row_col].sm (5 KiB) downloaded 59 time(s).
1 users liked this post
Radovan Omorjan 9/8/2016 2:40:00 PM
#15 Posted: 9/8/2016 2:40:01 PM
Radovan Omorjan

Radovan Omorjan

325 likes in 2052 posts.

Group: Moderator

Wrote

If we could use the array valued indices on the left hand side of assignments, this would be close to having range variables like in Mathcad.

SS-14 could be closed.




Sorry, Martin but it seems to me that at the moment we could use the array valued indices on the left hand side for the numerical or symbolical equal to, only. Not on the left hand side of the assignment operator. I hope I am(not) right.

Regards,
Ra
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#16 Posted: 9/8/2016 3:04:58 PM
Radovan Omorjan

Radovan Omorjan

325 likes in 2052 posts.

Group: Moderator

Wrote

Sorry for "Mathcaders Primes", Mathcad 11 did it simple because
it supported index [indices] as argment. Smath does not.
Though submatrix look alike between Smath/Mathcad, except for
the indexing, they are not the same ...
Explain: In Mathcad, if you want to mirror a matrix [think of
an image], you just need to reverse the cols order. Smath does
not support the reverse cols order.

If you think others do something useful: YES, but useless for
practical Engineering works involving specific search in matrix
unless the software has been designed for.

When working with matrices [Smath, Mathcad ...] you need a
"Matrix Treasury" of utilities. You will have more than expected
in the attached document.

Thanks Radovan, most interesting subject.

Jean

Forum ForLoopList.gif



Thank you Jean for the comment, and you are very welcome as always.

As Andrey introduced this new feature, you can just use intrinsic SS possibilities rather than writing new functions like your own, or as Davide wrote few ones in the post above, for extracting the values from a matrix in the way you want. I also mentioned, as you did, that this feature do not have neither Mathcad nor Prime(I think).

jean4.PNG

Regards,
Ra
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#17 Posted: 9/8/2016 9:30:05 PM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

The snipet does it nice, does not work in 5346, and very glad it
does not work. What I need is a function, and designed as such
fully flexible rather than a local result. There is a bit of story
behind "MatrixBlocUser". Mathcad 11.2a [2003] came with the Excel
read function ++++, how many have used/exchanged work in the forum ?
NONE !!! except during the stage of designing DAEP, the collab had
to read "SunSpot" from his own Excel file.

The 3 functions [matrix utilities] have been vital to me, let's see:
The Project Team constructs the pipe data ... so many cols wide, so
many rows long. The piping designer needs certain cols by the rows
of pipe sizes wrt the project. The purchasing department needs other
set of columns, the transport trucker other set of cols ...
and Jean [the Instrument man] needs his own set of cols/rows.
So, everybody is happy with the "MatrixBlocUser".

Jean

MatrixBlocUser.gif

Utilities Matrix RemToDo [select row_col].sm (24 KiB) downloaded 68 time(s).
1 users liked this post
Radovan Omorjan 9/9/2016 2:12:00 AM
#18 Posted: 9/10/2016 2:24:19 AM
Mike Kaganski

Mike Kaganski

184 likes in 434 posts.

Group: User

Wrote

we cannot generate symb vector here
because in SS we support definition after usage



Hm. I just don't seem to understand...
Why isn't possible to re-interpret el(X,range(1,5)) as mat(el(X,1),el(X,2),el(X,3),el(X,4),el(X,5),5,1)? Aren't these expressions equivalent in any case? If value of X is undefined, this doesn't seem to change the situation...
С уважением, Михаил Каганский
#19 Posted: 9/10/2016 5:34:07 AM
Radovan Omorjan

Radovan Omorjan

325 likes in 2052 posts.

Group: Moderator

Wrote

Wrote

we cannot generate symb vector here
because in SS we support definition after usage



Hm. I just don't seem to understand...
Why isn't possible to re-interpret el(X,range(1,5)) as mat(el(X,1),el(X,2),el(X,3),el(X,4),el(X,5),5,1)? Aren't these expressions equivalent in any case? If value of X is undefined, this doesn't seem to change the situation...



Thank you for your comment Mike. I did not understand this as well but had to accept what Andrey explained about it for granted.
BTW, this gave me headache many times when I had to define a symbolic vector, matrix (having the elements in standard notation like mat(el(X,1),el(X,2),el(X,3)...) with more than few variables. I hoped this might be the most simplest way.

There must be something simpler than this, or I just forgot how to perform this in as simpler way

Symbolic vector matrix

Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#20 Posted: 9/10/2016 6:36:15 AM
Martin Kraska

Martin Kraska

1222 likes in 2150 posts.

Group: Moderator

Wrote

You can test new functionality in SMath Studio in the Cloud.

Here is my sandbox to play: http://smath.info/cloud/worksheet/gYFgZBnd.

Best regards, Andrey Ivashov.



The sandbox example shows the use of matrices as indices. The question is, how the rules for such indices are.

A straightforward rule would be that whatever you provide as index structure, it is accessed by linear indexing from 1..length() of the index structure.

The following example shows that the actual behaviour is different. The index matrices are indexed column-wise and not row-wise as the usual linear indexing works.

I propose to change this in order to be consistent with general linear indexing.


Example (cloud)

linind.PNG

Martin Kraska Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
4 users liked this post
Radovan Omorjan 9/10/2016 8:29:00 AM, frapuano 9/10/2016 3:12:00 PM, Davide Carpi 9/19/2016 1:18:00 PM, Andrey Ivashov 9/19/2016 6:59:00 PM
  • New Posts New Posts
  • No New Posts No New Posts