1 страниц (17 вхождений)
Testing data type - Сообщения
#1 Опубликовано: 10.08.2010 19:06:30
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

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 Опубликовано: 10.08.2010 19:31:28
It's a first that came to my mind:

Maybe it is not a most elegant solution, but it works.
Regards.
Maybe it is not a most elegant solution, but it works.
Regards.
#3 Опубликовано: 10.08.2010 20:52:46
Another way of doing it. Take your pick.


Ed
#4 Опубликовано: 11.08.2010 02:16:31
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
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 Опубликовано: 11.08.2010 06:58:21
Radovan,
Thanks for pointing out my oversight.
My mind was stuck on a column vector like in Will's post.
Thanks for pointing out my oversight.
My mind was stuck on a column vector like in Will's post.
Ed
#6 Опубликовано: 11.08.2010 07:57:23
I will add IsMatrix function to the new version of SMath Studio.
#7 Опубликовано: 11.08.2010 08:17:08
WroteI 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 Опубликовано: 11.08.2010 09:16:46
WroteRadovan,
Thanks for pointing out my oversight.
My mind was stuck on a column vector like in Will's post.
You are welcome

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 Опубликовано: 11.08.2010 11:26:02
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.
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 Опубликовано: 11.08.2010 13:51:21
Why does this not work?


Will Massie
Mechanical Engineer
Oregon, USA
#11 Опубликовано: 11.08.2010 15:28:54
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
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 Опубликовано: 13.08.2010 12:59:35
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.
Just a suggestion.
Will Massie
Mechanical Engineer
Oregon, USA
#13 Опубликовано: 23.03.2016 15:19:48
WroteI 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 Опубликовано: 23.03.2016 15:53:59
WroteWroteI 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()
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
1 пользователям понравился этот пост
Chito 18.03.2022 00:32:00
#15 Опубликовано: 23.03.2016 17:15:28
#16 Опубликовано: 23.03.2016 19:05:04
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](/ru-RU/file/QhVFYv/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)

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).
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 Опубликовано: 23.03.2016 19:25:37
Thanks Davide,
I guessed right you would have wise guidance.
Mathcad "ifNaN", "ifIsScalar" OK ... other "if" ???
Jean
I guessed right you would have wise guidance.
Mathcad "ifNaN", "ifIsScalar" OK ... other "if" ???
Jean
1 страниц (17 вхождений)
-
Новые сообщения
-
Нет новых сообщений