Executing the following code , variables get reasigned with values form other variables.
x = MxFromString( "{{1,1,1},{1,1,1}}" ) ;
w = MxFromString( "{{1,1}}" );
for( i = 0 ; i < 10 ; i ++ )
{
z = w@x;
t = -1 * z ;
e = exp( t ) ;
d = 1 + e;
y = 1 / d;
}
I'm using AB 6.28.0 64bit, and am getting the same results as you - it seems to be occuring randomly - I stepped through your code several times in debug mode, and the unusual result in z occurred 3 times during one run, and only once on the others.
I did the matrix calcs by hand, and got a 3x1 vector of {2,2,2}, which is the same as what appears in z most of the time.
Instantiating z beforehand, with z = Matrix(3, 1, Null) ; outside the for() loop, seems to make no difference.
EDIT1:
Doing some more testing, stepping through it in debug mode again, the problem occurs randomly, but what seems to be happening, is that even though the debugger executes the line with t, for example, one of the other variables also gets changed. It doesn't just happen with the z variable.
Thanks to @fxshrat pointing me to changes in 6.25, I noticed that math functions such as sin(), cos(), log(), ln(), tanh(), sqrt(), etc.. with matrices as argument behave as if argument is passed as reference, modifying arguments' value
while passing arguments as reference does not seem to change anything
@phase21 What kind of problem it is? Pasting screenshots here is very easy - piece of cake. In some cases you can even drag and drop images straight to the editor. Just remember not to exceed allowed size (currently 1MB)
Here's an example of the screenshot with some more details regarding this topic:
Thank you for this report. This is being investigated. In the meantime a workaround exists. If you call single-argument standard math functions (sqrt, exp, log, sin/cos/tan/atan, etc) with matrices as input you can do this
x = MxFromString( "{{1,1,1},{1,1,1}}" ) ;
w = MxFromString( "{{1,1}}" );
for( i = 0 ; i < 10 ; i ++ )
{
z = w@x;
t = -1 * z ;
e = exp( t + 0 ) ; // Workaround: create temporary value that is passed as arg
d = 1 + e;
y = 1 / d;
}
UPDATE: The problem was diagnosed. When matrix variable was directly passed to single-argument math function (sqrt, exp, log, trigonometric, etc) its reference count was decreased so it could get freed and re-used prematurely. The above workaround is 100% safe solution for any version. The native fix will be included in 6.30.1 official release, so starting from 6.30.1 you won't need workaround.
@Tomasz I suggest taking this opportunity also to update the online reference pages and help/user guide for the single-argument standard math functions, adding the matrices as a possible input.