comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Need a function to multiply the elements of an array
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Need a function to multiply the elements of an array [message #4142 is a reply to message #4065] Fri, 28 April 1995 00:00 Go to previous messageGo to previous message
VUKOVIC is currently offline  VUKOVIC
Messages: 6
Registered: December 1994
Junior Member
In <3nohst$sun@pinot.umd.edu% barsam@Glue.umd.edu writes:

% In article <3nm2uk$qqq@pinot.umd.edu%,
% I wrote:
% %
% %Hi,
% %
% %I am looking for a routine to multiply the elements of an array.
% %Is there a faster way of doing it than the following?
% %
% %
% %function prod, x
% %n = n_elements(x)-1
% %z = 1.d0
% %for i = 0, n do z = z * x(i)
% %return, z
% %end
% %
% %
% %
% %BM
% %
%
% Thanks for the replies.
%
% z = exp(total(alog(x))) gives me about 60% savings. Not terribly
% fast but obviously better than the "for" loop.
%
% BM
%
%
That is strange (or I am strange), but I would think naively
expect that in the "for" loop you have only N multiplications, while
taking log of each number gives you M*N multiplications, where M is the
number of multiplications used to evaluate the log of a number.

I guess if going for speed, it would be fairly simple to write a fortran/c
routine to do it

Mirko

Mirko Vukovic | vukovic@uwmfe.neep.wisc.edu
Dept. of Nucl. Eng. and Eng. Phys. | mvukovic@wiscmacc.bitnet
U of Wisconsin -- Madison | phone: (608) 265-4069
1500 Johnson Drive; Madison WI 53706| fax: (608) 265-2364
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: ARMA (was Re: Need a function to multiply the elements of an array)
Next Topic: Re: strart up file in idl

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 16:31:35 PDT 2025

Total time taken to generate the page: 1.19793 seconds