Re: Could this be improved?---Continued

• To: mathgroup at smc.vnet.net
• Subject: [mg21805] Re: Could this be improved?---Continued
• From: "Jordan Rosenthal" <jr at ece.gatech.edu>
• Date: Fri, 28 Jan 2000 01:45:55 -0500 (EST)
• Organization: Georgia Institute of Technology, Atlanta GA, USA
• References: <86mdpv\$2f3@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Hi all,

First of all I wanted to say thanks.  I got more than ten replies (not all
were posted to the newsgroup) to my message and all replies were
informative.

To continue my learning experience, I wanted to take all the different
methods and compare the timings to see which runs fastest.  I tried the
following:

Timing /@ {f1[vSmall];, f2[vSmall];, f3[vSmall];, f4[vSmall];, f5[vSmall];,
f6[vSmall];, f7[vSmall];, f8[vSmall];, f9[vSmall];, f10[vSmall];,
f11[vSmall];, f12[vSmall];, f13[vSmall];, f14[vSmall];, f15[vSmall];}

where f1,f2,...,f15 are the different function implementations I received
(can you believe there were that many!).  This does not work.  I get 0
seconds for each.  I imagine this is because each f[vSmall] term in the list
is being evaluated before Timing is applied.  Is that correct?

So I have two more questions:

1) Is there any way to stop the function evaluation from happening until
Timing gets applied to it?  I looked at the Hold command and its variants,
but I could not figure out how best to apply it.  Am I on the wrong track?

2) I know you can use the Map function (or the /@ form) to apply a function
to a list of elements.  Is there a way to apply a list of functions to a
single element?  For example, it would be nice if I could apply each
function in the list{f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15} to
the vector vSmall.

Jordan

"Jordan Rosenthal" <jr at ece.gatech.edu> wrote in message
news:86mdpv\$2f3 at smc.vnet.net...
> Hi all,
>
> I wrote the following code which works correctly.  I was wondering,
however,
> if there was a way of doing the same thing that had more of a Mathematica
> approach.  I am new to Mathematica and am still trying to get a grasp on
how
> to program effectively within the environment.
>
> myMtx[v_] := Module[
>     nCols = Length[v];
>     nRows = 2nCols - 1;
>     c = ZeroMatrix[nRows, nCols];
>     For[i = 1, i <= nCols, i++,
>       ];
>     c
>     ]
>
> For example, myMtx[{1,2,3}] takes the vector {1,2,3} and turns it into the
> matrix {{1, 0, 0}, {2, 1, 0}, {3, 2, 1}, {0, 3, 2}, {0, 0, 3}} which looks
> like
>
> [ 1 0 0 ]
> [ 2 1 0 ]
> [ 3 2 1 ]
> [ 0 3 2 ]
> [ 0 0 3 ]
>
>
> Thanks,
>
> Jordan
>
>
>
>
>

```

• Prev by Date: Re: Improvements
• Next by Date: Re: How to Break[] out of nested loops?
• Previous by thread: Re: cellular automata & OOP stupid?
• Next by thread: Re: notebook