Hi,
it would be nice if there were functions to create identity matrixes, or ones, or zeros based only on the given dimension; for example :
ones(3) = {1;1;1} zeros(2) = {0;0} identity(2) = { 1 ; 0 0 ; 1 }
and also it would be useful then to have a function that return the size of a given element; for example:
P = {1; 2; 3} length(P) = 3 size(P) = {3; 1}
this two tools would be handy to deal with vectors and matrixes in a more automatic way.
Personally I use vectors to store variadic argument, and then use vector operations to get results I need. For example let it be vec y
a vector that store the y
coordinate of some points:
vec y = {y_1;y_2;y_3;...;y_n}
If want to calculate the sum of (y_i)^2
, it is incredibly easy, I just need to do the multiplication (vec y)^T * (vec y)
and get a neat result. Coversely if I need just the sum of y_i
it's more awkward since i would need to multiply the transpose of vec y
for a vectors of ones of the same size. If I could create this vectors of ones on the fly, based simply on the size of vec y
, then I could change the number of element of vec y
and automatically have a correct result without the need to manually create a vector of ones of the same size.
Further operation would be possible and would require less manual input.
Really is just a convoluted way to have for each loops in my odt.
Anonymous
That is a good suggestion. The symbolic math package which iMath uses (GiNaC) has the following functions which it would be easy to implement in iMath:
Would these functions cover all the operations you require?
That would be a great addition! For sure it would cover the use case I was thinking of, and then some more.
Check out the 2.3.1~beta8 version. Documentation is here: https://ooo-imath.sourceforge.io/wiki/index.php/Function#Built-in_functions_for_vectors_and_matrices)
So I did some test and found some troubles with identity and inverse matrix.
An inverse matrix obtained my the function
invertmatrix()
doesn't behave properly when evalueted, but a manually inserted inverted matrix works fine.I also found a weird behavior where the first
printval
statement doesn't evaluate correctly, but the following copies of the sameprintval
statements instead evaluate correctly.Have a look at the attached odt file (also pdf version of my output).
Last edit: Stefano 2021-08-24
Hi Stefano, thanks for your tests.
I think most of your problems are caused by the fact that you did not announce to iMath that A and B are matrices:
%%ii MATRIXDEF A
%%ii MATRIXDEF B
Thus A and B are treated as normal symbols, which explains A A^{-1} = 1.
you are correct.
I declared both matrices as you said and now it works fine.
Just to be clear, I need to declare beforehand even the matrices that are created by a function, like
B=invertmatrix(A)
, otherwise imath doesn't now how to handle them correctly. Anything else was an happy accident.I am curious: why do you have to rename the ginac function?
For example I see that
rows
has becomematrixrows
and so on.I'm just trying to avoid future name clashes. Also, names with underscore print badly in Office.