MathGroup Archive 1991

[Date Index] [Thread Index] [Author Index]

Search the Archive

My challenge

  • To: mathgroup at
  • Subject: My challenge
  • From: David Jacobson <jacobson at>
  • Date: Fri, 9 Aug 91 20:07:42 pdt

A couple of weeks ago I challenged the group to find better ways to
write expressions that operate on a column of a matrix.  It is clear
that I didn't express myself very clearly, bacause of the wide variety
of replies I got.  Several people suggested recursive solutions.  That
might work fine for small problems, but in my work I'm often dealing
with traces of I/O activity from a computer system, so the "matrix" is
really a list of ordered pairs that is frequently 10000 to 50000 pairs
long!  Recursion wouldn't cut it.  (One trace is over 500000 long, but
even my 23 MIPS HP workstation, Mathematica runs too slowly for that
one.)  Several people also suggested interactive ways of doing it, i.e.
they assumed that the list was held in a variable and I wanted to change
it in place.  I really wanted something that could operate on an
expression, producing another expression that could be used, for
example, in ListPlot.

I also got several suggestions of functions that could do it.  That was
not really what I had in mind:  I was looking for a way to do it
concisely with just built-in Mathematica operators.  But no such concise
way was forthcoming.  The best function was one suggested by 
Karl Frederick Arrington, who suggested 

    mapOnCol[ f_, m_List, column_Integer ] := 
	   	Transpose[MapAt[f, Transpose[m], {column}]];
    mapOnCol::usage = "mapOnCol[function,matrix,column]  \n
	     applies the function only to the the column specified.";


    RunningSum[v_] := Accumulate[Plus,v];

I have put these in a library that I load at the beginning of my
session.  Actually, I've changed his mapOnCol to OpOnCol, since to me
mapping means going down a list doing something to each element.

Now instead of writing


I just write OpOnCol[RunningSum,z,2]

Thanks Karl.

  -- David Jacobson

  • Prev by Date: Re: math2.0 rule ordering
  • Next by Date: calculus of variations
  • Previous by thread: Re: math2.0 rule ordering
  • Next by thread: calculus of variations