Testing data type

Testing data type - Сообщения

#1 Опубликовано: 10.08.2010 19:06:30
maweilian

maweilian

5 сообщений из 103 понравились пользователям.

Группа: 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 Опубликовано: 10.08.2010 19:31:28
Andrey Ivashov

Andrey Ivashov

2269 сообщений из 3730 понравились пользователям.

Группа: Super Administrator

It's a first that came to my mind:


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

Regards.
#3 Опубликовано: 10.08.2010 20:52:46
Edward Ulle

Edward Ulle

20 сообщений из 182 понравились пользователям.

Группа: Moderator

Another way of doing it. Take your pick.

Ed
#4 Опубликовано: 11.08.2010 02:16:31
Radovan Omorjan

Radovan Omorjan

325 сообщений из 2052 понравились пользователям.

Группа: 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 Опубликовано: 11.08.2010 06:58:21
Edward Ulle

Edward Ulle

20 сообщений из 182 понравились пользователям.

Группа: Moderator

Radovan,

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
Andrey Ivashov

Andrey Ivashov

2269 сообщений из 3730 понравились пользователям.

Группа: Super Administrator

I will add IsMatrix function to the new version of SMath Studio.
#7 Опубликовано: 11.08.2010 08:17:08
Radovan Omorjan

Radovan Omorjan

325 сообщений из 2052 понравились пользователям.

Группа: 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 Опубликовано: 11.08.2010 09:16:46
Radovan Omorjan

Radovan Omorjan

325 сообщений из 2052 понравились пользователям.

Группа: 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 Опубликовано: 11.08.2010 11:26:02
maweilian

maweilian

5 сообщений из 103 понравились пользователям.

Группа: 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 Опубликовано: 11.08.2010 13:51:21
maweilian

maweilian

5 сообщений из 103 понравились пользователям.

Группа: User

Why does this not work?

Will Massie Mechanical Engineer Oregon, USA
#11 Опубликовано: 11.08.2010 15:28:54
Radovan Omorjan

Radovan Omorjan

325 сообщений из 2052 понравились пользователям.

Группа: 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 Опубликовано: 13.08.2010 12:59:35
maweilian

maweilian

5 сообщений из 103 понравились пользователям.

Группа: 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 Опубликовано: 23.03.2016 15:19:48
Arie

Arie

93 сообщений из 285 понравились пользователям.

Группа: 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 Опубликовано: 23.03.2016 15:53:59
Davide Carpi

Davide Carpi

1415 сообщений из 2872 понравились пользователям.

Группа: 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 пользователям понравился этот пост
Chito 18.03.2022 00:32:00
#15 Опубликовано: 23.03.2016 17:15:28
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: 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 Опубликовано: 23.03.2016 19:05:04
Davide Carpi

Davide Carpi

1415 сообщений из 2872 понравились пользователям.

Группа: 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 Опубликовано: 23.03.2016 19:25:37
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

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

Jean
  • Новые сообщения Новые сообщения
  • Нет новых сообщений Нет новых сообщений