Wolfgang Meiners
2014-03-31
I wrote the following simple function which calculates the cross product of two vectors:
CP(a,b):= [a[2]*b[3]-a[3]*b[2], a[3]*b[1]-a[1]*b[3], a[1]*b[2]-a[2]*b[1]];
Now everything seems to work fine, but then i tried
C(b,a);
in the hope, to get the negative value of C(a,b). Nevertheless, wxmaxima hangs.
So what is going wrong?
I am running the newest version wxMaxima 13.04.0 available for osx:
System info
wxWidgets: 2.8.12
Unicode Support: yes
Maxima version: 5.30.0
Lisp: SBCL 1.0.55.0-abb03f
Thank you for any information
Joseph Cusumano
2014-03-31
Your function works fine on my system:
(%i1) CP(a,b):= [a[2]*b[3]-a[3]*b[2], a[3]*b[1]-a[1]*b[3], a[1]*b[2]-a[2]*b[1]]; (%o1) CP(a, b) := [a b - a b , a b - a b , a b - a b ] 2 3 3 2 3 1 1 3 1 2 2 1 (%i2) a:[a1,a2,a3]; b:[b1,b2,b3]; (%o2) [a1, a2, a3] (%o3) [b1, b2, b3] (%i4) CP(a,b)+CP(b,a); (%o4) [0, 0, 0]
I'm running Maxima 13.04.2 on an old XP system.
Wolfgang Meiners
2014-03-31
Can you try
kill(all); CP(a,b):= [a[2]*b[3]-a[3]*b[2], a[3]*b[1]-a[1]*b[3], a[1]*b[2]-a[2]*b[1]]; CP(a,b);
and then, without defining a and b,
CP(b,a);
the first function call (CP(a,b)) does work, the second leads to a hanging system in my version of maxima.
Wolfgang
Joseph Cusumano
2014-04-01
Wolfgang Meiners wrote the following on 3/31/2014 5:40 PM:
kill(all);
CP(a,b):= [a[2]b[3]-a[3]b[2], a[3]b[1]-a[1]!<-- I removed this symbol
b[3], a[1]b[2]-a[2]b[1]];
CP(a,b);
Yes, CP(b,a) hangs on mine too. As does CP(p,q). I don't see why you
would expect this to not cause problems, since Maxima does not know if
the arguments are lists as required. It certainly shouldn't hang. It
would be better if it displayed an error message. But it also doesn't
seem like a problem in any reasonable calculation for which the
arguments to CP are properly defined.
What is it you're trying to do?
Wolfgang Meiners
2014-04-01
"What is it you're trying to do?"
I am trying to understand what happens. I wrote this function - and i am not very experienced in writing programs for wxmaxima. After defining the function, i applied it to some arguments without defining these arguments. There was no problem. The following works on my system:
kill(all);
(%o0) done
CP(a,b):= [a[2]b[3]-a[3]b[2], a[3]b[1]-a[1]b[3], a[1]b[2]-a[2]b[1]];
(%o1) CP(a,b):=[a[2]b[3]−a[3]b[2],a[3]b[1]−a[1]b[3],a[1]b[2]−a[2]b[1]]
CP(x,y);
(%o2) [x[2]y[3]−y[2]x[3],y[1]x[3]−x[1]y[3],x[1]y[2]−y[1]x[2]]
CP(p,q);
(%o3) [p[2]q[3]−q[2]p[3],q[1]p[3]−p[1]q[3],p[1]q[2]−q[1]p[2]]
so there seems to be no need to define vectors before calculating the cross product. But then i tried to verify the antisymmetry of the cross product by writing
CP(a,b) + CP(b,a)
and then, the program hangs. I can write
CP(x,y) + CP(y,x); (%o5) [0,0,0]
so this seems to be related to the call CP(b,a) where the arguments are changed. I want to understand, what is going wrong in this situation to avoid such errors in future situations.
In my opinion, the main program should not know about the arguments of the function. The inside world of the function should be opaque to the main program. But this seems not to be the case. So can i use variables a,b in the main program? Obviously not. If i could use them, CP(b,a) should work as well, as CP(a,b) does.
Wolfgang
Albrecht Mueller
2014-04-02
I think this is a bug and therefore opened a ticket: #2715 A problem with subscripted variables
Wolfgang Meiners
2014-04-04
Hello Albrecht,
thank you for this confirmation
Wolfgang