RE: What makes things Listable?
- To: mathgroup at smc.vnet.net
- Subject: [mg26317] RE: [mg26302] What makes things Listable?
- From: "David Park" <djmp at earthlink.net>
- Date: Sun, 10 Dec 2000 21:38:02 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Chris,
I think you want to use the Apply function. Applying f to a list {x,y,z} is
the same as f[x,y,z]. Here is an example.
f[x_, y_, z_] := Sqrt[x^2 + y^2 + z^2]
f @@ {x, y, z}
Sqrt[x^2 + y^2 + z^2]
This is most convenient when you want to apply f to a list of vectors which
contain the arguments for f:
f @@ # & /@ {{x, y, z}, {p, q, r}, {1, 2, 3}}
{Sqrt[x^2 + y^2 + z^2], Sqrt[p^2 + q^2 + r^2], Sqrt[14]}
David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/
> From: Chris Johnson [mailto:cjohnson at shell.faradic.net]
To: mathgroup at smc.vnet.net
>
> I'm using the "Finance Essentials" package and want to use the Value
> command over a list of bonds. For those not familiar with the package,
> there is a structure called Bonds which defines the coupon, maturity,
> etc. for a bond. The Value command takes three arguements, Bond,
> SettlementDate, YieldToMaturity and returns a price.
>
> Having vectors of Bonds, Dates, and Yields, I want to create a vector
> of prices. My first guess was to try the following command:
> Value[Transpose[{bondlist,datelist,yields}]]
>
> This returned the result
> Value[{{bond[1],valdate[1],yield[1]},...}]
>
> My next step was to use Map[Value,Transpose[...]] which returned a list
> like {Value[{bond,valdate,ytm}],...} where the parameters for Value are
> surrounded by curly braces. Value wouldn't evaluate over parameters in
> this form.
>
> The solution I found for now is to create my own fuction
>
> cjValueList[{x_,y_,z_}]:=Value[x,y,z]
>
> and then mapping cjValueList provides the table I seek. I have run into
> this general problem of wanting to get rid of the outer level of curly
> braces before, and wonder if there is a more general solution then this
> hack redefinition of the function?
>
> Thanks,
> Chris Johnson
>
>
>