operating on matrix/vector cells



Hi,

That's a thing that is extremely easy in openoffice spreadsheet, but
I don't know how to do it nicely in maxima.

I have 15 different measurements of several variables. Currently I
have put them in matrix rows:

(%i1) load(ezunits);

(%i2) M[0]: 60.34`g;
(%i3) m[6]:    (7.02-0.32) ` g;
(%i4) m[8]:    (9.1-0.76) ` g;
(%i5) m[10.5]: (11.0-0.06) ` g;

(%i6) measurements:      P:
matrix(['s   ,'l   ,'m           ,'t_1   , 't_2   , 't_3   , 't_4   , 't_5   ],
       [20`cm,20`cm,m[6]         ,0.466`s, 0.466`s, 0.466`s, 0.464`s, 0.463`s],
       [20`cm,20`cm,m[8]         ,0.416`s, 0.421`s, 0.420`s, 0.421`s, 0.418`s],
       [20`cm,20`cm,m[10.5]      ,0.369`s, 0.365`s, 0.373`s, 0.370`s, 0.377`s],
       [20`cm,20`cm,m[10.5]+m[8] ,0.280`s, 0.282`s, 0.283`s, 0.278`s, 0.282`s],
       [15`cm,25`cm,m[6]         ,0.312`s, 0.312`s, 0.313`s, 0.312`s, 0.311`s],
       [15`cm,25`cm,m[8]         ,0.282`s, 0.282`s, 0.283`s, 0.278`s, 0.278`s],
       [15`cm,25`cm,m[10.5]      ,0.245`s, 0.246`s, 0.248`s, 0.244`s, 0.245`s],
       [15`cm,25`cm,m[10.5]+m[8] ,0.188`s, 0.189`s, 0.188`s, 0.189`s, 0.186`s],
       [15`cm,20`cm,m[6]         ,0.351`s, 0.347`s, 0.349`s, 0.347`s, 0.351`s],
       [15`cm,20`cm,m[8]         ,0.317`s, 0.315`s, 0.315`s, 0.315`s, 0.313`s],
       [15`cm,20`cm,m[10.5]      ,0.278`s, 0.274`s, 0.275`s, 0.275`s, 0.274`s],
       [15`cm,20`cm,m[10.5]+m[8] ,0.213`s, 0.211`s, 0.209`s, 0.210`s, 0.210`s],
       [34`cm,6`cm  ,m[6]        ,1.552`s, 1.560`s, 1.537`s, 1.557`s, 1.538`s],
       [6`cm, 34`cm, m[6]        ,0.108`s, 0.107`s, 0.107`s, 0.106`s, 0.106`s],
       [34`cm,2.2`cm,m[6]        ,2.829`s, 2.829`s, 2.829`s, 2.829`s,
       2.829`s]);


Then I need to calculate stuff for each row:
- an average of t_1,t_2,t_3,t_4,t_5,
- then calculate the result of a function call g_1(M,m,s,l,t)
- put the result in an additional column (different result for each
  row) or just put it in a new matrix (vertical vector).

currently I do it in a quite convoluted way:

(%i7) t_avg(i):=1/5*sum(P[i][j], j, 4, 8);
(%i8) g_1(M,m_,s_,l_,t_2):=(s_^2*(2*M+m_))/(2*t_2^2*l_*m_);
(%i9) for i thru 15 do for j thru 1 do g_1_[i,j]: g_1(M[0],P[i+1][3],P[i+1][1],P[i+1][2],t_avg(i+1)  )``m/s^2$

(%i10) g_result_1: genmatrix(g_1_,15,1);


do you have any better way to do this?

As another side question - in (%i8) you will notice that I used '_'
in variable names. 's_' instead of 's', 'm_' instead of 'm', and so
on. I did this because I was afraid that using 's' would conflict
with ezunits "second" called `s, and that 'm' would conflict with
already declared m[6], m[8]. Am I right to be afraid of such naming
conflicts?

And another question: should I used ezunits, or units ? Or sth. else?

thanks a lot for your help
-- 
Janek Kozicki                               http://janek.kozicki.pl/ |