Testing data type

Testing data type - Messages

#1 Posted: 8/10/2010 7:06:30 PM
maweilian

maweilian

5 likes in 103 posts.

Group: User

The solve function gives a real number if there is only one solution, but gives a matrix if there are multiply solutions. As in the screen shot below:



or



This is fine until you need to use a looping worksheet that needs to do matrix operations on the result. Is there an easy way to test whether a variable contains a matrix or a real number? This would allow for conditional statements that would perform one series of operations if the variable contains a real number but another series if the variable contains a matrix.

Thanks,
Will
Will Massie Mechanical Engineer Oregon, USA
#2 Posted: 8/10/2010 7:31:28 PM
Andrey Ivashov

Andrey Ivashov

2271 likes in 3734 posts.

Group: Super Administrator

It's a first that came to my mind:


Maybe it is not a most elegant solution, but it works.

Regards.
#3 Posted: 8/10/2010 8:52:46 PM
Edward Ulle

Edward Ulle

20 likes in 182 posts.

Group: Moderator

Another way of doing it. Take your pick.

Ed
#4 Posted: 8/11/2010 2:16:31 AM
Radovan Omorjan

Radovan Omorjan

325 likes in 2052 posts.

Group: Moderator

Hello TheWizEd,

I think your example is not quite correct. It will check the difference between
1. scalar or single element matrix
and
2. matrices with at least two rows

Therefore matrices like
[MATH lang=eng]a←mat(5,1,1)[/MATH] or [MATH lang=eng]b←mat(1,2,3,1,3)[/MATH]
will be regardes as "scalar"

There might be an intrinsic function like IsVector, IsMatrix but considering that we can have matrices with constants, undefined variables, functions, functions returning single element, returning vectors, returning matrices as well as nested matrices - I do not believe that we can get out of this in order to distinguish what is vector-matrix and what is not.
The only thing I can relize at the moment is that if you can get
[MATH lang=eng]el(a,1)=5[/MATH] or [MATH lang=eng]el(a,1,1)=5[/MATH]
and
[MATH lang=eng]el(a,1)—x+y[/MATH] or [MATH lang=eng]el(a,1,1)—x+y[/MATH]
could be regarded as vector. If you can not have the result (numerical, symbolical) of a variable, function etc. with only single index (actually with single index equals to one) - this could be regarded as matrix. This might be under discussion and not acceptable though.

Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#5 Posted: 8/11/2010 6:58:21 AM
Edward Ulle

Edward Ulle

20 likes in 182 posts.

Group: Moderator

Radovan,

Thanks for pointing out my oversight.

My mind was stuck on a column vector like in Will's post.
Ed
#6 Posted: 8/11/2010 7:57:23 AM
Andrey Ivashov

Andrey Ivashov

2271 likes in 3734 posts.

Group: Super Administrator

I will add IsMatrix function to the new version of SMath Studio.
#7 Posted: 8/11/2010 8:17:08 AM
Radovan Omorjan

Radovan Omorjan

325 likes in 2052 posts.

Group: Moderator

Wrote

I will add IsMatrix function to the new version of SMath Studio.


Thanks Andrey ,

It will solve the problems Will mentioned in the first post.

Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#8 Posted: 8/11/2010 9:16:46 AM
Radovan Omorjan

Radovan Omorjan

325 likes in 2052 posts.

Group: Moderator

Wrote

Radovan,

Thanks for pointing out my oversight.

My mind was stuck on a column vector like in Will's post.


You are welcome . Also the functions "cols" and "stack" could be used if there were row matrix, with the same logic as you used.
Btw, I forgot to mention something. It is interesting that you used # character in the varaible name. I was a bit confused (# is mentioned in the context of placeholder character) but I realised that # could be used in the variable name. If used as a first character the Text region will be inserted (the same as " ).

Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#9 Posted: 8/11/2010 11:26:02 AM
maweilian

maweilian

5 likes in 103 posts.

Group: User

To all,

Thanks for the pointers.

Andrey, an "IsMatrix" function would be a great help. Normally, I would consider trying to create a plugin myself to do this (it would have been a great learning exercise), but I am currently real busy with other work. I just need to get a worksheet that does what I need for now.
Will Massie Mechanical Engineer Oregon, USA
#10 Posted: 8/11/2010 1:51:21 PM
maweilian

maweilian

5 likes in 103 posts.

Group: User

Why does this not work?

Will Massie Mechanical Engineer Oregon, USA
#11 Posted: 8/11/2010 3:28:54 PM
Radovan Omorjan

Radovan Omorjan

325 likes in 2052 posts.

Group: Moderator

Hello Will,

I can reproduce this as well.

It seems that whatever the argument of IsMatrix was, it returns "false". A bug maybe or something else?

Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#12 Posted: 8/13/2010 12:59:35 PM
maweilian

maweilian

5 likes in 103 posts.

Group: User

I was also thinking that an "IsDefined()" function would also be useful to test whether a variable contained a value (previously defined) or whether it was empty (not yet defined, or undefined due to an error). This might be useful for error handling purposes within a worksheet.

Just a suggestion.
Will Massie Mechanical Engineer Oregon, USA
#13 Posted: 3/23/2016 3:19:48 PM
Arie

Arie

93 likes in 285 posts.

Group: User

Wrote

I will add IsMatrix function to the new version of SMath Studio.




I know this is old thread, but was IsMatrix ever implemented or similar functionality?
Feel free to join the SMath Studio Users Discord Channel: https://discord.gg/PayZpJW
#14 Posted: 3/23/2016 3:53:59 PM
Davide Carpi

Davide Carpi

1417 likes in 2873 posts.

Group: Moderator

Wrote

Wrote

I will add IsMatrix function to the new version of SMath Studio.




I know this is old thread, but was IsMatrix ever implemented or similar functionality?


If you download the plugin Custom Functions, you can use GetType()

2016-03-23 19_57_02-SMath Studio Desktop - [CustomFunctions_examples.sm_].png






If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
1 users liked this post
Chito 3/18/2022 12:32:00 AM
#15 Posted: 3/23/2016 5:15:28 PM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

Wrote

I know this is old thread, but was IsMatrix
ever implemented or similar functionality?



The Smath "IsDefined" works for matrices > the default .
Does not work for vector . "IsAssigned(object) would be
more inductive. Don't know how to return the last message.

Forum IsDefined.gif

#16 Posted: 3/23/2016 7:05:04 PM
Davide Carpi

Davide Carpi

1417 likes in 2873 posts.

Group: Moderator

Jean,

when an error is thrown the result is not stored -> this means that in SMath Studio is not possible to define a matrix with empty placeholders -> your IsAssigned will never works under these assumptions...

Hence, also IsDefined() works correctly because the first assignment of XY is not overwritten nor deleted, hence it is still in memory (XY is defined in the worksheet memory).

2016-03-23 22_44_42-SMath Studio Desktop - [Page1_].png

BTW, you shouldn't use "object" as target of the function [el(object,i,j):whatever], you have to use a brand new matrix defined inside the function (because the pass-by-reference, if you use an argument as target of some calculation you are modifying it)
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
#17 Posted: 3/23/2016 7:25:37 PM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

Thanks Davide,
I guessed right you would have wise guidance.
Mathcad "ifNaN", "ifIsScalar" OK ... other "if" ???

Jean
  • New Posts New Posts
  • No New Posts No New Posts