ListManipulationQuestion
- To: mathgroup at smc.vnet.net
- Subject: [mg93149] ListManipulationQuestion
- From: lynette <xiaochu at gmail.com>
- Date: Wed, 29 Oct 2008 05:47:58 -0500 (EST)
Hi: I try to encode a hash table in the name of list. successors[{s_Integer, {{nhu_Integer, nhd_Integer}, {nlu_Integer, nld_Integer}}}] := { {1, {{nhu + 1, nhd}, {nlu, nld}}}, {1, {{nhu, nhd + 1}, {nlu, nld}}}, {2, {{nhu, nhd}, {nlu + 1, nld}}}, {2, {{nhu, nhd}, {nlu, nld + 1}}} } successors[{1, {{2, 3}, {0, 2}}}] {{1, {{3, 3}, {0, 2}}}, {1, {{2, 4}, {0, 2}}}, {2, {{2, 3}, {1, 2}}}, {2, {{2, 3}, {0, 3}}}} I want to find the price of successor nodes given the price of current node nextprice[p_, n_] := price[p] Total[Flatten[(n[[2]] - p[[2]]) {{\ [Delta]hu, \[Delta]hd}, {\[Delta]lu, \[Delta]ld}}]] It works for single node: price[{1, {{2, 3}, {0, 2}}}] = 100 price[{2, {{2, 3}, {0, 3}}}] = nextprice[{1, {{2, 3}, {0, 2}}}, {2, {{2, 3}, {0, 3}}}] 90.9091 However, it doesn't work when I tried to map it out: input: nextprice[{1, {{0, 0}, {0, 0}}}, #] & /@ successors[{1, {{0, 0}, {0, 0}}}] output: {120., 83.3333, 110., 90.9091} input: price[{1, {{1, 0}, {0, 0}}}] output: price[{1, {{1, 0}, {0, 0}}}] I cannot assign the price to each successor nodes. Does anybody know what is wrong with it? thanks alot.