Re: pure function
- To: mathgroup at smc.vnet.net
- Subject: [mg87363] Re: [mg87332] pure function
- From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
- Date: Tue, 8 Apr 2008 07:17:00 -0400 (EDT)
- References: <200804080934.FAA11916@smc.vnet.net>
On 8 Apr 2008, at 18:34, haitomi wrote: > Hello All, > > I need help with two pure functions > > 1) Li[Ranlist,x] that return a list of x element selected at random > from Ranlist. (Is there any way to gennerate random from Ranlist? I > have RanList=Range[-100,100]) > > 2) the function 4Sumf[x] is computing the sum of 4 squares of x. If > I have x=1, this function will gennerate 1^2+0^2+0^2+0^2, if x=4 > then 2^2+0^2+0^2+0^2, if x=7 2^2+1^2+1^2+1^2 > > Is anyone out there have any idea? > Thanks All, > Tomi > With Mathematica 6: 1) Selections with replacement or without replacement? With replacement: RandomChoice[Range[-100, 100], 6] {58, 13, -51, 66, -40, -69} without replacement: RandomSample[Range[-100, 100], 6] {-38, 67, 83, 79, 3, -3} (2). PowersRepresentations[1, 4, 2] {{0, 0, 0, 1}} PowersRepresentations[7, 4, 2] {{1, 1, 1, 2}} All this has to be (and can be) done quite differently with earlier versions of Mathematica but as you do not specify your version I assume you have the latest. Andrzej Kozlowski
- References:
- pure function
- From: haitomi <tpnycity@yahoo.com>
- pure function