If I defined variables
a=5; b=3;
what is the fastest/most elegant way to get?
m = [5,3]
Is there something better than
m= Matrix(Eval({a,b}));
And why does
m=[Eval(a),Eval(b)]
not work?Any links to related posts are welcome
For me, the easiest way to get to the result is
m=matrix(a) |/ matrix(b);
oh, Matrix evaluates the list? got it!
Then
m= Matrix({a,b});
works as well And what's the reason that
doesn't work?
Using Matrix( {a, b} ) is probably the easiest way. One way that I use commonly is [](0,1) |/ a |/ b
Matrix( {a, b} )
[](0,1) |/ a |/ b
As for your second question, matrices are special in JSL and are not evaluated as you would expect. Normally you can put a JSL expression anywhere in the JSL script and only the final argument would get returned. However, with matrices (probably for the code to be more optimized and speedy), you cannot put expressions in the matrix elements and expect that it will be populated with the number returned by that expression. Expressions are strictly _not_ allowed in matrices, only numbers are allowed. This is also why variables don't work within matrices, as variables only make sense when they are evaluated as an expression.
OK understood.Thanks a lot for the explanation.
@ErraticAttack wrote:you cannot put expressions in the matrix elements and expect that it will be populated with the number returned by that expression.
you cannot put expressions in the matrix elements and expect that it will be populated with the number returned by that expression.
Is a good wording It could work but you cannot expect that it will work:
a=5; matrix(a/b); // -> works<BR />matrix(char(a)) // -> doesn't matrix({char(a)}) // --> doesn't (I hoped this could be a workaround ...)
</CODE></P><P><FONT face="arial,helvetica,sans-serif"><CODE class=" language-jsl">So ..
@ErraticAttack wrote:Expressions are strictly _not_ allowed in matrices, only numbers are allowed.
Expressions are strictly _not_ allowed in matrices, only numbers are allowed.
seems to be slightly too strict - but a good approach "to be on the safe side"