mat_unblocker not working




On Sun, 15 Nov 2009, Julie Sandberg wrote:

< Leo,
< 
< Thank you for pointing that out to me. Actually, I am using r as the radius and u as a scaling factor. But I should be using r twice like that. After renaming the first one r1, this problem is fixed.
< 
< However, I am still having a similar problem later on in the code. When I define the velocity and acceleration vectors, both add extra brackets. Again, using mat_unblocker does not work to remove a level of brackets, and I still cannot use 'solve' for F=ma.
< 
< /*Body CG Motion in Inertial n-Frame*/
< rc_n:Cbn.rc_b;
< 
< vc_n:diff(rc_n,t)+Wco_n~rc_n;
< 
< ac_n:diff(vc_n,t)+Wco_n~vc_n;
< 
< Thank you for your time!
< ~Julie~
< 

Julie, Please reply to the list. 
You've been tripped up a few times by Maxima's treatment of
matrices vs. lists. Unfortunately, vectors are implemented as nx1 matrices,
so to access elements, you must address them as x[i,1].

I should also point out that it appears that you confuse the equation of
two objects ("=") versus the solution of equations. See fsoln below.


Here are the changes I would suggest: (+ implies change to)

(%i58) system("diff -b -u /tmp/omat.mac /tmp/mat.mac");
--- /tmp/omat.mac       2009-11-16 07:55:23.000000000 +0000
+++ /tmp/mat.mac        2009-11-16 07:55:04.000000000 +0000
@@ -14,7 +14,10 @@
 u3 : transpose([0,0,1]);

 infix("~");
-"~"(x,y):=matrix([x[2]*y[3]-x[3]*y[2]],[x[3]*y[1]-x[1]*y[3]],[x[1]*y[2]-x[2]*y[1]])$
+"~"(x,y):= block([x:x,y:y],
+  if listp(x) then x : genmatrix(lambda([i,j],x[i]),3,1),
+  if listp(y) then y : genmatrix(lambda([i,j],y[i]),3,1),
+
matrix([x[2,1]*y[3,1]-x[3,1]*y[2,1]],[x[3,1]*y[1,1]-x[1,1]*y[3,1]],[x[1,1]*y[2,1]-x[2,1]*y[1,1]]))$


 /*Alpha is the angle of rotation of the bar along x, and Beta is the
 * angle of rotation of the cylinder*/
@@ -48,12 +51,12 @@
 integ:(r.r)*ident(3)-transpose(r).r;

 /*Use Clyindrical Coordinates*/
-integ2:ev(integ,x=u*r*sin(theta),y=h,z=u*r*cos(theta)),expand,ratsimp,trigsimp;
+integ2:ev(integ,x=u*sin(theta),y=h,z=u*cos(theta)),expand,ratsimp,trigsimp;

 /*,y=h,z=u*r*cos(theta)]),expand,ratsimp,trigsimp;*/


-matrix([z^2+y^2,-sin(theta)*u*x*y,-sin(theta)*u*y^2,-sin(theta)*u*y*z,-sin(theta)*u*x*z,-sin(theta)*u*y*z,-sin(theta)*u*z^2],[-sin(theta)*u*x*y,-sin(theta)*u*y^2,-sin(t\
heta)*u*y*z,z^2+sin(theta)^2*u^2*x^2,z^2+sin(theta)^2*u^2*y^2,(sin(theta)^2*u^2+1)*z^2],-y*z],[-sin(theta)*u*x*z,-sin(theta)*u*y*z,-sin(theta)*u*z^2,-y*z,y^2+sin(theta)^\
2*u^2*x^2,(sin(theta)^2*u^2+1)*y^2,sin(theta)^2*u^2*z^2+y^2])
+/*matrix([z^2+y^2,-sin(theta)*u*x*y,-sin(theta)*u*y^2,-sin(theta)*u*y*z,-sin(theta)*u*x*z,-sin(theta)*u*y*z,-sin(theta)*u*z^2],[-sin(theta)*u*x*y,-sin(theta)*u*y^2,-sin\
(theta)*u*y*z,z^2+sin(theta)^2*u^2*x^2,z^2+sin(theta)^2*u^2*y^2,(sin(theta)^2*u^2+1)*z^2],-y*z],[-sin(theta)*u*x*z,-sin(theta)*u*y*z,-sin(theta)*u*z^2,-y*z,y^2+sin(theta\
)^2*u^2*x^2,(sin(theta)^2*u^2+1)*y^2,sin(theta)^2*u^2*z^2+y^2])*/

 /****************************************************************/
 /*Calculate Mass*/
@@ -157,27 +160,26 @@


 /*Necessary Conditions*/
-nc:[Force[1],Force[2],Force[3],Mbearing[1],Mbearing[2],Mbearing[3]];
+nc:[Force[1,1],Force[2,1],Force[3,1],Mbearing[1,1],Mbearing[2,1],Mbearing[3,1]];


 /*Solve for Forces*/
-fsoln:solve(nc,[fax,fay,faz,fbx,fby,fbz]);
+fsoln : map("=",[fax,fay,faz,fbx,fby,fbz],nc);

 /*Solve Moment Equations*/
-msoln:solve(Torque[1],Torque[2],Torque[3],[mx,my,tau]);
+msoln:solve([Torque[1,1],Torque[2,1],Torque[3,1]],[mx,my,tau]);

 /*Equations of Motion*/
-EOM:solve(msoln[3],diff(omega,t));
-*/
+EOM:solve(msoln[1][3],diff(omega,t));
+

I think the last line should be EOM : diff(omega,t) = msoln[1][3];

< ----- Original Message -----
< From: "Leo Butler" <l.butler at ed.ac.uk>
< To: "Julie Sandberg" <jsandberg at neo.tamu.edu>
< Cc: maxima at math.utexas.edu
< Sent: Saturday, November 14, 2009 3:34:15 AM GMT -06:00 US/Canada Central
< Subject: Re: [Maxima] mat_unblocker not working
< 
< 
< 
< On Fri, 13 Nov 2009, Julie Sandberg wrote:
< 
< < Hi,
< < 
< < I am working on a dynamaics assigment using Maxima. I need to ultimately solve for forces and moments, but throughout my script Maxima creates nested lists with excessive [ and ]'s where I should have simple matrices. For instance, in the attached code, I calculate a MOI integrand using 
< < 
< < /*MOI Integrand*/
< < integ:(r.r)*ident(3)-transpose(r).r;
< < 
< < Then, I would like to convert these values to cylindrical coordinates:
< < 
< < /*Use Clyindrical Coordinates*/
< < integ2:ev(integ,x=u*r*sin(theta),y=h,z=u*r*cos(theta)),expand,ratsimp,trigsimp;
< 
< Julie, if I understand your problem correctly, then [u,h,theta] are
< cylindrical coordinates, while you define r:[x,y,z] a few lines above in
< the attached .mac file. It seems to me that you should not have 'r' in
< the above substitutions.
< 
< integ2:ev(integ,x=u*sin(theta),y=h,z=u*cos(theta)),expand,ratsimp,trigsimp;
< 
< I suspect this is the root of your problem below.
< 
< Leo
< 
< < 
< < Because integ is a nested list, ev cannot evaluate at these values. Is there any way to "un-nest" integ? I have this same problem through  my code.
< < 
< < Thank you for your time.
< < 
< < -- 
< < Julie Sandberg
< < M.S. Aerospace Engineering
< < Dynamics and Control
< < Texas A&M University
< < 
< 
< -- 
< The University of Edinburgh is a charitable body, registered in
< Scotland, with registration number SC005336.
< 
< 
< -- 
< Julie Sandberg
< M.S. Aerospace Engineering
< Dynamics and Control
< Texas A&M University
< 
< 

-- 
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.