numbers and vectors

numbers and vectors - Сообщения

#1 Опубликовано: 14.01.2012 23:51:27
Davide Carpi

Davide Carpi

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

Группа: Moderator

Hi,

I think will be useful a function that show if a variabile it's a number (something like the classic isNaN() or also length(var) may be modified to return 0 or 1 in case var is a number)

regards
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
#2 Опубликовано: 15.01.2012 02:41:11
Radovan Omorjan

Radovan Omorjan

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

Группа: Moderator

Hello,

I agree. As far as I know, there is only IsString() and IsDefined() functions among IsThisorThat() functions available. I believe that other functions like IsArray() or IsScalar() would be useful.

Regarding your question, IsString(arg) function will return 1 if the argument variable -arg- is string variable or function returning string, 0 otherwise (number, scalar, vector, matrix, function returning the ones).

Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#3 Опубликовано: 15.01.2012 17:11:19
Davide Carpi

Davide Carpi

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

Группа: Moderator



at the moment I'm using this workaround

If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
1 пользователям понравился этот пост
Radovan Omorjan 15.01.2012 17:58:00
#4 Опубликовано: 15.01.2012 18:07:35
Radovan Omorjan

Radovan Omorjan

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

Группа: Moderator

Hello,

There is a minor problem with your workaround. Suppose you have a matrix with only one element (this is allowed in SMath)

[MATH=eng]b←mat(5,1,1)[/MATH]
[MATH=eng]el(b,1)=5[/MATH]
[MATH=eng]el(b,1,1)=5[/MATH]

Your function will not recognize it as an array. It may cause problems sometimes, isn't it?

[MATH=eng]IsArray(b)=0[/MATH]

Regards,
Radovan

EDIT: On the other hand, every array is made by using mat() function i.e.
[MATH=eng]A←mat(1,2,1,3,2,2)[/MATH]
num2str( A )="mat(1,2,1,3,2,2)"
[MATH=eng]b←mat(5,1,1)[/MATH]
num2str( b )="mat(5,1,1)"
Unfortunately, I did not figure out how to use all of this to make a IsArray() function which will work with string, scalar and array arguments.
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#5 Опубликовано: 15.01.2012 20:35:05
Davide Carpi

Davide Carpi

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

Группа: Moderator

with 1x1 vectors I don't have problems (I'm using SMath 0.90)


Now I've replaced
num2str(length())[/code] with less expensive [code]num2str()[/code] and I've replaced [code]findstr("l"[/code] with [code]findstr("m"

and I've fixed a little bug with words that contains the findstr argument and a big bug with strings with whitespaces introducing
IsString()

edit: here there is the file with the two functions IsArray.sm
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
#6 Опубликовано: 15.01.2012 21:31:14
Radovan Omorjan

Radovan Omorjan

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

Группа: Moderator

Hello,

Thank you for your efforts. It is a bit tricky and unusual, but works most of the time. What do I mean by that. Just look at the picture (your function used) and it seems to be problematic for the arrays with units and nested arrays.

Maybe some more adjustments?

Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#7 Опубликовано: 15.01.2012 23:15:48
Radovan Omorjan

Radovan Omorjan

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

Группа: Moderator

Hello,

This might be useful, I think.


Regards,
Radovan

EDIT: I just replaced the ans with this expression and it works as well with scalar and units (problem was with scalar and units including 'm in them)
ans:=findstr(_e,"mat("+1
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#8 Опубликовано: 16.01.2012 04:17:25
Davide Carpi

Davide Carpi

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

Группа: Moderator

Great hints
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
  • Новые сообщения Новые сообщения
  • Нет новых сообщений Нет новых сообщений