[q-lang-cvs] qcalc/examples example.qcalc, 1.5, 1.6 simpson.q, 1.1, NONE
Brought to you by:
agraef
From: Albert G. <ag...@us...> - 2007-11-26 21:34:02
|
Update of /cvsroot/q-lang/qcalc/examples In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv31779 Modified Files: example.qcalc Removed Files: simpson.q Log Message: reverted examples.qcalc to initial version; Eddie's examples can now be found in eds-example.qcalc Index: example.qcalc =================================================================== RCS file: /cvsroot/q-lang/qcalc/examples/example.qcalc,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** example.qcalc 15 Nov 2007 10:18:09 -0000 1.5 --- example.qcalc 26 Nov 2007 21:33:58 -0000 1.6 *************** *** 1,6 **** ! // qcalc 1.0, created Thu Nov 15 11:21:15 2007 -*-Q-*- -*- coding: UTF-8 -*- ! // [((0,1),"*** Erathosthenes' prime sieve ***"),((2,0),"Q stream of *all* primes"),((2,1),"= primes"),((3,0),"The first 50 primes"),((3,1),"= list $ take 50 B3"),((4,0),"The 111th prime"),((4,1),"= B3!111"),((5,0),"Product of the first 50"),((5,1),"= prd B4"),((6,1),"(This is a HUGE number, make the column bigger to see it all.)"),((8,1),"*** Linear Regression (Eddie Rucker) ***"),((9,0),"1"),((9,1),"3"),((10,0),"2"),((10,1),"5"),((11,0),"3"),((11,1),"7"),((12,0),"4"),((12,1),"9"),((13,0),"5"),((13,1),"10"),((14,0),"6"),((14,1),"13"),((15,0),"Least squares:"),((15,1),"= regress A10:A15 B10:B15"),((16,0),"Enter X:"),((16,1),"7"),((17,0),"Value at X:"),((17,1),"= B16 B17"),((19,1),"*** Normal Distribution (Eddie Rucker) ***"),((20,0),"Enter A:"),((20,1),"-1"),((21,0),"Enter B:"),((21,1),"1"),((22,0),"P(X>=A):"),((22,1),"= normal_above B21"),((23,0),"P(X<=B):"),((23,1),"= normal_below B22"),((24,0),"P(A<=X<=B):"),((24,1),"= normal B21 B22"),((26,1),"*** Playing with sums etc. ***"),((26,2),"Squares"),((26,3),"Cubes"),((27,1),"1"),((27,2),"= square B28"),((27,3),"= cube B28"),((28,1),"2"),((28,2),"= square B29"),((28,3),"= cube B29"),((29,1),"3"),((29,2),"= square B30"),((29,3),"= cube B30"),((30,1),"4"),((30,2),"= square B31"),((30,3),"= cube B31"),((31,1),"5"),((31,2),"= square B32"),((31,3),"= cube B32"),((32,1),"6"),((32,2),"= square B33"),((32,3),"= cube B33"),((33,1),"7"),((33,2),"= square B34"),((33,3),"= cube B34"),((34,1),"8"),((34,2),"= square B35"),((34,3),"= cube B35"),((35,1),"9"),((35,2),"= square B36"),((35,3),"= cube B36"),((36,1),"10"),((36,2),"= square B37"),((36,3),"= cube B37"),((38,0),"Sum"),((38,1),"= sum B28:B37"),((38,2),"= sum C28:C37"),((38,3),"= sum D28:D37"),((39,0),"Product"),((39,1),"= prd B28:B37"),((39,2),"= prd C28:C37"),((39,3),"= prd D28:D37"),((40,1),"Note that the range B28:B37 becomes a Q list:"),((41,1),"= B28:B37"),((44,1),"*** Geometric series ***"),((45,0),"Enter Q:"),((45,1),"= 1/3"),((46,0),"Series:"),((46,1),"= geom_series B46"),((47,0),"1"),((47,1),"= B$47!A48"),((48,0),"2"),((48,1),"= B$47!A49"),((49,0),"3"),((49,1),"= B$47!A50"),((50,0),"4"),((50,1),"= B$47!A51"),((51,0),"5"),((51,1),"= B$47!A52"),((52,0),"6"),((52,1),"= B$47!A53"),((53,0),"7"),((53,1),"= B$47!A54"),((54,0),"8"),((54,1),"= B$47!A55"),((55,0),"9"),((55,1),"= B$47!A56"),((56,0),"10"),((56,1),"= B$47!A57"),((57,0),"11"),((57,1),"= B$47!A58"),((58,0),"12"),((58,1),"= B$47!A59"),((59,0),"13"),((59,1),"= B$47!A60"),((60,0),"14"),((60,1),"= B$47!A61"),((61,0),"15"),((61,1),"= B$47!A62"),((63,1),"Some calculations with rationals:"),((64,0),"Op1"),((64,1),"= 5%3"),((65,0),"Op2"),((65,1),"= 81%53"),((66,0),"Sum"),((66,1),"= B65+B66"),((67,0),"Product"),((67,1),"= B65*B66"),((68,0),"Quotient"),((68,1),"= B65 % B66"),((70,1),"Complex numbers:"),((71,0),"2^(1/i)"),((71,1),"= 2^(1/i)"),((72,0),"log2 of that"),((72,1),"= lg B72"),((73,0),"abs, arg of the log2"),((73,1),"= (abs B73,arg B73)"),((75,1),"Complex rationals:"),((76,1),"= (1+:2)%(3+:4)"),((77,1),"= square (5+:-5%18)")] ! // [(6,37)] ! // [(0,139),(1,308),(2,120),(3,163),(4,188)] // Start of script. Please do not remove this line. --- 1,6 ---- ! // qcalc 1.0, created Mon Nov 26 22:34:23 2007 -*-Q-*- -*- coding: UTF-8 -*- ! // [((0,1),"Erathosthenes' prime sieve"),((0,3),"Playing with sums etc."),((0,4),"Squares"),((0,5),"Cubes"),((1,3),"1"),((1,4),"= square D2"),((1,5),"= cube D2"),((2,0),"Q stream of *all* primes"),((2,1),"= primes"),((2,3),"2"),((2,4),"= square D3"),((2,5),"= cube D3"),((3,0),"The first 50 primes"),((3,1),"= list $ take 50 B3"),((3,3),"3"),((3,4),"= square D4"),((3,5),"= cube D4"),((4,0),"The 111th prime"),((4,1),"= B3!111"),((4,3),"4"),((4,4),"= square D5"),((4,5),"= cube D5"),((5,0),"Product of the first 50"),((5,1),"= prd B4"),((5,3),"5"),((5,4),"= square D6"),((5,5),"= cube D6"),((6,1),"(This is a HUGE number, make the column bigger to see it all.)"),((6,3),"6"),((6,4),"= square D7"),((6,5),"= cube D7"),((7,3),"7"),((7,4),"= square D8"),((7,5),"= cube D8"),((8,1),"Some calculations with rationals:"),((8,3),"8"),((8,4),"= square D9"),((8,5),"= cube D9"),((9,0),"Op1"),((9,1),"= 5%3"),((9,3),"9"),((9,4),"= square D10"),((9,5),"= cube D10"),((10,0),"Op2"),((10,1),"= 81%53"),((10,3),"10"),((10,4),"= square D11"),((10,5),"= cube D11"),((11,0),"Sum"),((11,1),"= B10+B11"),((12,0),"Product"),((12,1),"= B10*B11"),((12,2),"Sum"),((12,3),"= sum D2:D11"),((12,4),"= sum E2:E11"),((12,5),"= sum F2:F11"),((13,0),"Quotient"),((13,1),"= B10 % B11"),((13,2),"Product"),((13,3),"= prd D2:D11"),((13,4),"= prd E2:E11"),((13,5),"= prd F2:F11"),((14,3),"Note that the range D2:D11"),((15,1),"Complex numbers:"),((15,3),"becomes a Q list:"),((16,0),"2^(1/i)"),((16,1),"= 2^(1/i)"),((16,3),"= $D$2:$D$11"),((17,0),"log2 of that"),((17,1),"= lg B17"),((18,0),"abs, arg of the log2"),((18,1),"= (abs B18,arg B18)"),((19,3),"Geometric series:"),((20,1),"Complex rationals:"),((20,2),"Enter Q:"),((20,3),"= 1/3"),((21,1),"= (1+:2)%(3+:4)"),((21,2),"Series:"),((21,3),"= geom_series D21"),((22,1),"= square (5+:-5%18)"),((22,2),"1"),((22,3),"= D$22!C23"),((23,2),"2"),((23,3),"= D$22!C24"),((24,2),"3"),((24,3),"= D$22!C25"),((25,2),"4"),((25,3),"= D$22!C26"),((26,2),"5"),((26,3),"= D$22!C27"),((27,2),"6"),((27,3),"= D$22!C28"),((28,2),"7"),((28,3),"= D$22!C29"),((29,2),"8"),((29,3),"= D$22!C30"),((30,2),"9"),((30,3),"= D$22!C31"),((31,2),"10"),((31,3),"= D$22!C32"),((32,2),"11"),((32,3),"= D$22!C33"),((33,2),"12"),((33,3),"= D$22!C34"),((34,2),"13"),((34,3),"= D$22!C35"),((35,2),"14"),((35,3),"= D$22!C36"),((36,2),"15"),((36,3),"= D$22!C37")] ! // [] ! // [(0,155),(1,404),(2,57),(3,174),(4,120),(5,163)] // Start of script. Please do not remove this line. *************** *** 19,48 **** primes = sieve {2..}; sieve {N|Ns} = {N|sieve {M:M in Ns,M mod N<>0}}; - - /* Simple regression (Eddie Rucker). */ - - regress X Y = \Z . A + B * Z - where B = (sxy X Y) / (sxy X X), - A = (mean Y) - B * (mean X); - - mean L = sum L / #L; - sxy X Y = (sum $ zipwith (*) X Y) - (sum X * sum Y) / #X; - - /* Normal distribution (Eddie Rucker). - - normal A B => probability of (A<=X<=B) - e.g.: normal (-1) 1 => 0.682688 - - normal_below A => probability of (X<=A) - normal_above A => probability of (X>=A) */ - - import simpson; - - normal = integrate normal_f; - normal_f X = 0.3989422804014327 * exp (-0.5*X*X); - - normal_below A = 0.5 + integrate normal_f 0.0 A if A > 0; - = 0.5 - integrate normal_f 0.0 A if A < 0; - = 0.5 otherwise; - - normal_above A = 1.0 - normal_below A; --- 19,20 ---- --- simpson.q DELETED --- |