Re: need help
- To: mathgroup at smc.vnet.net
- Subject: [mg87325] Re: need help
- From: dh <dh at metrohm.ch>
- Date: Tue, 8 Apr 2008 05:33:33 -0400 (EDT)
- References: <ftcoug$ksr$1@smc.vnet.net>
Hi Tomi, for random numbers, see RandomInteger or RandomReal in the manual. They can generates lists. The function can be written e.g. as: FourSumf[n_]:=Module[{eq}, eq={x1^2+x2^2+x3^3+x4^2==n, 0<=x1<=x2<=x3<=x4, Element[{x1,x2,x3,x4},Integers]}; {x1,x2,x3,x4}/.ToRules[Reduce[eq]] ] here we used that the sum of squares is n, that 0<=xi, we sorted xi ascending and we request that x must be integers. Finally Reduce does the actual work. hope this helps, Daniel 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? For example 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 then 2^2+1^2+1^2+1^2 > > Is anyone out there have any ideas? > Thanks All, > Tomi >