Dimensions of a vector,matrix function?

Dimensions of a vector,matrix function? - Сообщения

#1 Опубликовано: 25.09.2010 17:18:13
Radovan Omorjan

Radovan Omorjan

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

Группа: Moderator

Hello Andrey,

Let's define a vector, matrix function (function returning vector or matrix). For example:
[MATH=eng]f(x)←mat(1,x/{1-x},x^2,1,x^2,x^3,2,3)[/MATH]
We can see the dimensions of vector, matrix it returns - but only with symbolic equal to:
[MATH=eng]rows(f(a))—2[/MATH]
[MATH=eng]cols(f(a))—3[/MATH]
[MATH=eng]length(f(x))—6[/MATH]
Numerical equal to will not work for the previous functions. The error will be if the arguments of "f" are not defined. Actually we can get the dimensions by simple using some defined variables or constants as arguments, say:
[MATH=eng]rows(f(0))=2[/MATH]
[MATH=eng]cols(f(0))=3[/MATH]
[MATH=eng]length(f(0))=6[/MATH]
The problem is that this is no "bullet proof" because if we use, say:
[MATH=eng]length(f(1))=#@#[/MATH]
The error will be issued (division by zero) - one of the "f" function elements is problematic.

To make myself clear. Why am I asking this? For instance, we can not use rows, cols or length functions in for lops directly. For instance, this will not work
[MATH=eng]for(i,range(1,rows(f(a))),for(j,range(1,cols(f(a))),el(A,i,j)←el(f(5),i,j)))[/MATH]
if variable "a" is not previously defined. However, if it was previously defined but if the "f" function "does not like it" - the error will be isued.

Sometimes we just have to do this. My question is - Is there any way to make this to work? Actually, rows, cols and length to work the same with simbolic equal to and numerical equal to. The argument to the function "f" in this case is irelevant - the point is that function "f" has only one argument - nothing else.

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

Radovan Omorjan

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

Группа: Moderator

[FIXED]

[MATH=eng]f(x)←mat(1/x,{1-x}/x,4-x,2/x,3/x,5-x^2,2,3)[/MATH]
[MATH=eng]rows(f(x#))=2[/MATH]
[MATH=eng]cols(f(x#))=3[/MATH]
[MATH=eng]length(f(x#))=6[/MATH]

Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
  • Новые сообщения Новые сообщения
  • Нет новых сообщений Нет новых сообщений