From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/87548 Path: news.gmane.org!not-for-mail From: Jeong Dal Newsgroups: gmane.comp.tex.context Subject: Re: Simple command with variable number of arguments Date: Sat, 24 May 2014 15:55:21 +0900 Message-ID: References: <9CFDA0D3-CC58-4A92-AE16-6FFE7B56D6EC@me.com> <537FA66D.3000608@wxs.nl> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="Boundary_(ID_Klks6RhoNLHcNdnuxdA8Jw)" X-Trace: ger.gmane.org 1400914548 10081 80.91.229.3 (24 May 2014 06:55:48 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 24 May 2014 06:55:48 +0000 (UTC) To: Hans Hagen , ntg-context@ntg.nl Original-X-From: ntg-context-bounces@ntg.nl Sat May 24 08:55:43 2014 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from balder.ntg.nl ([5.39.185.229]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Wo5rr-0004tp-7m for gctc-ntg-context-518@m.gmane.org; Sat, 24 May 2014 08:55:43 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 978AB1022D for ; Sat, 24 May 2014 08:55:42 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id Exkq+2zx2MVr for ; Sat, 24 May 2014 08:55:42 +0200 (CEST) Original-Received: from balder.ntg.nl (localhost [IPv6:::1]) by balder.ntg.nl (Postfix) with ESMTP id 2029D10210 for ; Sat, 24 May 2014 08:55:39 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id B0A61101E8 for ; Sat, 24 May 2014 08:55:33 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id nQp3mFgUG8Or for ; Sat, 24 May 2014 08:55:32 +0200 (CEST) Original-Received: from filter4-til.mf.surf.net (filter4-til.mf.surf.net [194.171.167.220]) by balder.ntg.nl (Postfix) with ESMTP id 32394101E3 for ; Sat, 24 May 2014 08:55:32 +0200 (CEST) Original-Received: from nk11p03mm-asmtp002.mac.com (nk11p03mm-asmtp002.mac.com [17.158.232.237]) by filter4-til.mf.surf.net (8.14.3/8.14.3/Debian-9.4) with ESMTP id s4O6tPJV017522 for ; Sat, 24 May 2014 08:55:31 +0200 Original-Received: from apple.ssu.ac.kr (apple.ssu.ac.kr [203.253.9.6]) by nk11p03mm-asmtp002.mac.com (Oracle Communications Messaging Server 7u4-27.08(7.0.4.27.7) 64bit (built Aug 22 2013)) with ESMTPSA id <0N6200IKPGKAKO40@nk11p03mm-asmtp002.mac.com> for ntg-context@ntg.nl; Sat, 24 May 2014 06:55:24 +0000 (GMT) In-reply-to: <537FA66D.3000608@wxs.nl> X-Mailer: Apple Mail (2.1874) X-MANTSH: 1TEIXREEbG1oaGkdHB0lGUkdDRl5PWBoaGxEKTEMXGx0EGx8SBBscHwQdHhAbHho fGhEKWE0XSxEKbX4XGhEKTFkXGxobGxEKWUkXEQpZXhdjY3kRCkNOF0sbHhpiTk0bdRhEdRl4c wceZRocHx9lGBEKWFwXGQQaBBsbB01OHxgYGBlLBRsdBBsfEgQbHB8EHR4QGx4aHxsRCl5ZF2F eT0gZEQpMRhdia2sRCkNaFxgaGQQYHxkEEwQcEQpCXhcbEQpEWBcYEQpEXhcYEQpCRhdlbxhyH 0d7XVMTQhEKQkUXbmt5HBpHbVlTaQERCkJOF2xwYHlAHWJSaRpiEQpCTBdkXE1mU1JhWE5ZbRE KQmwXYXhrYE1BbV1JZ10RCkJAF2JJGhxlc35gaRhFEQpwaBdtWhNhHBpvbENnHBEKcGgXZGRIZ VIbcnkTf1kRCnBoF2NSX39SXl1iTEVuEQpwaBdoWnNuRl5aHEdMGxEKcGgXb2xIbU9zbEBTGgU RCnBrF29+ZUhwflwFa2cbEQpwSxdjGEtQaWxiRVh/XBEKcGwXaGYZZ01zRnoBR2cRCnBMF2xhZ 09GS1scQgFDEQ== X-CLX-Spam: false X-CLX-Score: 1011 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.11.96,1.0.14,0.0.0000 definitions=2014-05-24_01:2014-05-23,2014-05-24,1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 suspectscore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=7.0.1-1402240000 definitions=main-1405240094 X-Bayes-Prob: 0.0001 (Score 0, tokens from: ntg-context@ntg.nl, base:default, @@RPTN) X-CanIt-Geo: ip=17.158.232.237; country=US; region=California; city=Cupertino; latitude=37.3042; longitude=-122.0946; http://maps.google.com/maps?q=37.3042,-122.0946&z=6 X-CanItPRO-Stream: uu:ntg-context@ntg.nl (inherits from uu:default, base:default) X-Canit-Stats-ID: 0VM5GTptS - 496a1f7be87b - 20140524 (trained as not-spam) X-Scanned-By: CanIt (www . roaringpenguin . com) on 194.171.167.220 X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.14 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ntg-context-bounces@ntg.nl Original-Sender: ntg-context-bounces@ntg.nl Xref: news.gmane.org gmane.comp.tex.context:87548 Archived-At: --Boundary_(ID_Klks6RhoNLHcNdnuxdA8Jw) Content-type: text/plain; charset=euc-kr Content-transfer-encoding: quoted-printable Dear Hans, Here is the file in my desktop. The reason I didn=A1=AFt define =A1=B0sgn=A1=B1 in the function = =A1=B0uppertri=A1=B1 is that it is inherited from the call of = =A1=B0determinant=A1=AF. However, I put =A1=B0sgn=3D1=A1=B1 so that the function =A1=B0uppertri=A1=B1= works independently. I checked the function =A1=B0uppertri=A1=B1 and found that it worked = fine. Here is a sample file. \environment MatrixLuacode \starttext \getbuffer[luaMatrix] \startformula\startalign \startluacode local mat =3D {{0, 2, 4, -4, 1},{0, 0, 2, 3 , 4}, {2, 2, -6, 2, 4 }, = {2,0 , -6, 9, 7},{2, 2, -6, 2, 4 },{2, 2, -6, 2, 4 }} -- local mat =3D {{1,2,3},{3,4,5},{3,4,5},{3,4,5},{3,4,5}} context.NC("\\text{Given Matrix}\\quad\\Rightarrow\\quad") context.NC() matrixOP.write(mat) context.NR() context.NC() context("\\text{Upper Triangular}\\quad\\Rightarrow\\quad") mat =3D matrixOP.upperTri(mat) context.NC() matrixOP.write(mat) context.NR() \stopluacode \stopalign\stopformula \stoptext Sometimes, I got =A1=B0-0=A1=B1 as an entry of matrix after calculation = but I couldn=A1=AFt resolve it(I asked about it to this list before).=20 Thank you. Best regards, Dalyoung --Boundary_(ID_Klks6RhoNLHcNdnuxdA8Jw) Content-type: application/octet-stream; x-unix-mode=0644; name=MatrixLuacode.tex Content-transfer-encoding: 7bit Content-disposition: attachment; filename=MatrixLuacode.tex \startenvironment MatrixLuacode \startbuffer[luaMatrix] \startluacode matrixOP = matrixOP or {} -- recommended: use namespace matrixOP.symMatrix = function(sym, x, y) -- symMatrix("a", "m", "n") local entry local mrow={} local mm={} for i=1, 2 do -- first two rows mrow={} for j=1, 2 do entry=sym.."_{"..i..j.."}" table.insert(mrow, entry) end entry="\\cdots" table.insert(mrow, entry) entry=sym.."_{"..i..y.."}" table.insert(mrow, entry) table.insert(mm,mrow) end entry = {"\\vdots","\\vdots","\\ddots","\\vdots"} --3rd row table.insert(mm,entry) mrow={} for j=1, 2 do -- last row entry=sym.."_{"..x..j.."}" table.insert(mrow, entry) end entry="\\cdots" table.insert(mrow, entry) entry=sym.."_{"..x..y.."}" table.insert(mrow, entry) table.insert(mm,mrow) return mm end matrixOP.write = function (t) context.startmatrix{left = "\\left(\\,", right = "\\,\\right)"} for _, r in ipairs(t) do for _, c in ipairs(r) do context.NC(c) end context.NR() end context.stopmatrix() end matrixOP.writeDet = function (t) context.startmatrix{left = "\\left|\\ ", right = "\\ \\right|"} for _, r in ipairs(t) do for _, c in ipairs(r) do context.NC(c) end context.NR() end context.stopmatrix() end matrixOP.rowChange = function(t, i, j) -- interchange two rows(i-th, j-th) t[i] , t[j]= t[j], t[i] end matrixOP.rowMult = function(t, i, m) -- replace i-th row with m*(i-th row) local len len = #(t[i]) for k = 1, len do t[i][k] = m*t[i][k] end end matrixOP.rowMultSum = function(t, i, j, m) -- replace i-th row with i-th row + m*(j-th row) local len len = #(t[1]) for k = 1, len do t[i][k] = t[i][k] + m*t[j][k] end end matrixOP.transpose = function(m) -- transpose of a matrix local temp local mT={} local mTrow for j = 1, #m[1] do mTrow={} for i=1, #m do temp = m[i][j] table.insert(mTrow, temp) end table.insert(mT, mTrow) end return mT end matrixOP.inner = function (u, v) -- inner product of two vectors temp=0 if #u == #v then for i=1, #u do temp = temp + u[i]*v[i] end end return temp end matrixOP.product = function(m1, m2) -- product of two matrices local temp local m3={} local mrow if #m1[1] == #m2 then for i = 1, #m1 do mrow={} for j=1, #m2[1] do temp = 0 for k=1, #m1[1] do u = m1[i][k]*m2[k][j] temp = temp + u end table.insert(mrow, temp) end table.insert(m3, mrow) end end return m3 end matrixOP.searchRow = function(m, i) local pv, pr pr = #m + 1 for k=i+1, #m do pv=m[k][i] if pv == 0 then k = k+1 else pr = k break end end if pr <= #m then return pr else return 0 end end matrixOP.upperTri = function(m) local pivot, pRow, multiple local temp temp = m sgn= 1 for i=1, #temp-1 do pivot = temp[i][i] if pivot == 0 then pRow = matrixOP.searchRow(temp, i) if pRow==0 then -- context("Singular Matrix") break end matrixOP.rowChange(temp, i, pRow) sgn=(-1)*sgn end for k=i+1, #temp do multiple = -temp[k][i]/temp[i][i] matrixOP.rowMultSum(temp, k, i,multiple) end end return temp end matrixOP.determinant = function(m) local det, sgn if #m ==#m[1] then det=1 sgn=1 matrixOP.upperTri(m) for i = 1, #m do det = det*m[i][i] end det = sgn*det else det = 0 end -- context(det) return det end \stopluacode \stopbuffer \stopenvironment --Boundary_(ID_Klks6RhoNLHcNdnuxdA8Jw) Content-type: text/plain; CHARSET=US-ASCII Content-transfer-encoding: 7BIT --Boundary_(ID_Klks6RhoNLHcNdnuxdA8Jw) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://tex.aanhet.net archive : http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________ --Boundary_(ID_Klks6RhoNLHcNdnuxdA8Jw)--