Article View: aus.stats.s
Article #16162A tiny problem to warn off for-loops.
From: Bill Venables
Date: Sun, 26 Jan 1992 07:27
Date: Sun, 26 Jan 1992 07:27
22 lines
1639 bytes
1639 bytes
The following is a miniscule problem I occasionally give to students to warn them off using nested for-loops in S at just about any cost. Problem: A random 2x2 matrix has the form _ _ A = | a b | | c d | - - where a,b,c and d are independent uniform random digits, i.e. in the set 0,1,...,9. Using an enumerative method in S find the exact distribution of det(A) and plot it as a "high density" plot. The literalist solution using four for-loops is utterly impractical. The most swish solution I have come up with uses no explicit loops, has only four statements, and works in practically no time, but it does not make use of the fact that the resuting distribution will clearly be symmetric about 0. I would be interested to see if anyone can find a more effective solution. [BTW It's no accident I slipped a "c" into the problem as a variable...] -- Bill Venables, Dept. of Statistics, | Email: venables@stats.adelaide.edu.au Univ. of Adelaide, South Australia. | Tel: +61 8 228 5412 Fax: ...232 5670
Technical Details
Message-ID:
<1271@spam.ua.oz>Path:
arc1-ca.pugleaf.net!sparky!uunet!think.com!spool.mu.edu!munnari.oz.au!yoyo.aarnet.edu.au!sirius.ucs.adelaide.edu.au!spam!wvenableShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fa931,632f0a34e4ad4bd5,start X-Google-Attributes: gidfa931,public X-Google-ArrivalTime: 1992-01-26 13:31:22 PST Path: arc1-ca.pugleaf.net!sparky!uunet!think.com!spool.mu.edu!munnari.oz.au!yoyo.aarnet.edu.au!sirius.ucs.adelaide.edu.au!spam!wvenable From: wvenable@spam.ua.oz (Bill Venables) Newsgroups: aus.stats.s Subject: A tiny problem to warn off for-loops. Message-ID: <1271@spam.ua.oz> Date: 26 Jan 92 07:27:59 GMT Article-I.D.: spam.1271 Organization: Stats Pure & Applied Maths, Uni of Adelaide, Australia Lines: 22