Symbolic matrix, vector ?

Symbolic matrix, vector ? - Messages

#1 Posted: 1/17/2012 2:43:58 AM
Radovan Omorjan

Radovan Omorjan

325 likes in 2052 posts.

Group: Moderator

Hello,

There were recently introduced few SMath functions which require a symbolic vectors as arguments. Just take a look at this simple example of calculating Jacobi matrix.


In this example, there were used symbolic vectors x and y using the elements with the same name - x(1),x(2) and y(1),y(2). I used two ways to define them - the direct assignment and by using for loop. Do not know any other way. I was just wondering if there might be another more elegant way to define symbolic vectors, matrices like the ones presented.

It crossed my mind something like this - to use a 3 arguments matrix function:
x:=matrix(2,1,x)
to give:
[MATH=eng]x—mat(el(x,1),el(x,2),2,1)[/MATH]
or:
Z:=matrix(2,1,x)
to give:
[MATH=eng]Z—mat(el(x,1),el(x,2),2,1)[/MATH]

This will work, of course, provided the third argument to be symbolic (undefined) variable or function.

Any other suggestions or ideas?

Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
#2 Posted: 1/17/2012 4:41:43 AM
Andrey Ivashov

Andrey Ivashov

2269 likes in 3729 posts.

Group: Super Administrator

Hello Radovan!

Do you mean some built-in function like this?


(download example)

Regards.
#3 Posted: 1/17/2012 5:06:52 AM
Radovan Omorjan

Radovan Omorjan

325 likes in 2052 posts.

Group: Moderator

Yes Andrey, that's it - very clever and interesting realization

It would be nice to have a built-in function like you described. It crossed my mind just to extend the matrix() function to matrix(3) in order to have such and similar functionality in filling a matrix, but did not come to my mind your solution. It seems that this function might be quite useful in matrix calculations.

On the other hand, I will definitely put this function as a "snippet". Thank you.

BTW, in order to make vectors we could make correction in above matrix(3) function or make a vector(2).

[MATH=eng]vector(n,f(1))←line(for(j←1,j≤n,j←j+1,el(result,j)←f(j)),result,2,1)[/MATH]
[MATH=eng]f(j)←el(x,j)[/MATH]
[MATH=eng]vector(3,f(j))—mat(el(x,1),el(x,2),el(x,3),3,1)[/MATH]

Rather useful for matrix elementwise operation (like vectorization in Mathcad)
[MATH=eng]f(j,k)←el(x,j,k)*e^el(y,j,k)[/MATH]
[MATH=eng]matrix(2,2,f(j,k))—mat(e^el(y,1,1)*el(x,1,1),e^el(y,1,2)*el(x,1,2),e^el(y,2,1)*el(x,2,1),e^el(y,2,2)*el(x,2,2),2,2)[/MATH]
[MATH=eng]f(j)←el(x,j)/el(y,j)[/MATH]
[MATH=eng]vector(3,f(j))—mat(el(x,1)/el(y,1),el(x,2)/el(y,2),el(x,3)/el(y,3),3,1)[/MATH]
[MATH=eng]x←mat(1,-1,6,3,1)[/MATH] [MATH=eng]y←mat(3,5,4,3,1)[/MATH]
[MATH=eng]vector(length(x),f(j))—mat(1/3,-1/5,3/2,3,1)[/MATH]

Actually, we have to pay attention on the function and varible names (f(2) and f(1) are functions with row, column indexes - x and y are global variables) but it is good enough

Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
  • New Posts New Posts
  • No New Posts No New Posts