Re: powersum with a function with variable count of parameters
- To: mathgroup at smc.vnet.net
- Subject: [mg25273] Re: [mg25262] powersum with a function with variable count of parameters
- From: Richard Palmer <mapsinc at bellatlantic.net>
- Date: Sun, 17 Sep 2000 17:33:39 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
on 9/17/00 4:47 AM, Klamser at Klamser at t-online.de wrote:
> Hi,
>
> how can I write a function f[x_,xi__]=10^x+10^xi, that returns
> f[1,2,3]->10^1+10^2+10 ^3.
>
> When i use the above definition, I only get
>
> 10^1+10^2^3
>
> But I want to get
>
> 10^1+10^2+10 ^3
>
> Regrads, Peter
>
>
>
Try PowerSum[args__]:=Plus@@{10^#&/@List[args])
The args parameter has two (2) underscores following it. This permits 1 or
more arguments. List[args] turns the arguments into a list. the function
10^# is mapped onto each element of the list (creating another list) and the
elements of the list are finally summed.
Regards, Richard Palmer
- Follow-Ups:
- Re: Re: powersum with a function with variable count of parameters
- From: Otto Linsuain <linsuain+@andrew.cmu.edu>
- Re: Re: powersum with a function with variable count of parameters