Re: Best way to determine # of entries in a list?
- To: mathgroup at smc.vnet.net
- Subject: [mg42036] Re: [mg42004] Best way to determine # of entries in a list?
- From: Selwyn Hollis <selwynh at earthlink.net>
- Date: Tue, 17 Jun 2003 05:43:10 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Something like alist = {1, 2, 3, 4, 5, 6}; poly[x_] := x^2 + x; solns = x /. NSolve[Length[alist] == poly[x], x] Or @@ IntegerQ /@ Rationalize[solns] perhaps? ----- Selwyn Hollis http://www.math.armstrong.edu/faculty/hollis On Monday, June 16, 2003, at 03:57 AM, cdj wrote: > Hi, > > Example problem: > > To streamline the input of systems of linear equations, i'm setting up > a function that accepts simply a flat list as argument. The first nxn > entries are the rows of the matrix, and the last n are the target > point (= b). This gives the length of the argument list as n^2 + n. > > I'd like to have a little bit of input error/type checking in the > function. For this example, given a list, I'd like to test whether or > not there exists an n such that length(list) = n^2 + n. > > The quickest/easiest way I know how to do it for this example problem > is to test for integer-hood on sqrt[4*length(list) + 1] (yes = good > data type). > > Q1: Does anybody know of a quicker/better/more elegant way to perform > this test? > > Q2: In general, suppose i want to test (the length of) my list against > an arbitrary polynomial P(n). What's the best way to do this? > > thanks for any insights, > > cdj > >