On Fri, Mar 5, 2010 at 9:50 AM, Janek Kozicki <janek_listy at wp.pl> wrote:
> That's a thing that is extremely easy in openoffice spreadsheet, but
> I don't know how to do it nicely in maxima.
I've often thought about a spreadsheet interface for Maxima.
Maybe there is some way to wedge Maxima into an existing
spreadsheet as the computational engine ...
Something to think about.
> 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).
Here's how I would go about it. I'd separate the different kinds
of data rather than trying to smash them all into one container.
The (undocumented, sorry) defstruct function creates aggregates
of dissimilar data with named fields. "@" references fields.
T : submatrix (P, 1, 2, 3);
T_avg : makelist (apply ("+", T[i]) / length (T[i]), i, 1, length (T));
defstruct (foo (M, m, s, l, t));
g_1 (x) := x at s^2 * (2 * x at M + x at m)/(2 * x at t^2 * x at l * x at m);
makelist (new (foo (M[0], P[i, 3], P[i, 1], P[i, 2], T_avg[i])), i, 1,
length(P));
map (g_1, %);
L : map (lambda ([e], e `` m/s^2), %);
transpose (matrix (L));
grind (%);
which yields
matrix([25*(x at m+120.68 ` g)*x at s^2
/(2*(t_5+t_4+t_3+t_2+t_1)^2*x at l*x at m)
`` m/s^2],[8.792665186036517 ` m/s^2],
[8.803359532524322 ` m/s^2],[8.7503437352016 ` m/s^2],
[9.193571636105242 ` m/s^2],[8.788803762253819 ` m/s^2],
[8.841545115073782 ` m/s^2],[8.975535176055383 ` m/s^2],
[9.24259066549705 ` m/s^2],[8.78007275630779 ` m/s^2],
[8.769854864407794 ` m/s^2],[8.935733999037103 ` m/s^2],
[9.206672555905925 ` m/s^2],[7.6350581655724 ` m/s^2],
[8.824244329345792 ` m/s^2],[6.2411655776461 ` m/s^2])$
Perhaps you're going to paste the results into a document.
The ` operator is TeX-able, maybe that's useful to you.
tex (whatever ` m/s^2);
=> $${\it whatever}\;{{\mathrm{m}}\over{\mathrm{s}^2}}$$
> 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?
Yes, assigning a value to a symbol which is used in different
contexts is likely to lead to confusion;
Maxima for the most part doesn't distinguish different ways
to use the same symbol. Also, variables in Maxima functions
have so-called dynamic scope, which can lead to extremely
subtle unexpected behavior.
> And another question: should I used ezunits, or units ? Or sth. else?
ezunits works OK for this problem, doesn't it?
The units package isn't as nice, I don't think, and anyway
it appears to be broken. Disclaimer: I wrote ezunits.
If there is some feature related to units which you would like
to see, I'd be interested to hear about it.
best
Robert Dodier