Dear Hans,
Thank you for the correction.
> your "decimal j" makes string while a number is expected
>
> here mp.print is clever enough to return a number
>
> label(textext("A"),(
> i*u,
> lua("mp.print(MP.data[" & decimal i & "][1])")
> ));
> message(lua("mp.print(MP.data[" & decimal i & "][1])"));
Now I got the working code.
It calculates the list of 4-dimensional vectors and draw a line graph which
shows the change of each component of vectors.
Here is the code. There may be several points which can be written more nicely.
Thanks again.
Best regards,
Dalyoung
\startluacode
local matT = {{0,0,1,1/3},{1,0,0,1/3},{0,1/2,0,1/3},{0,1/2,0,0}}
local matOld = {{1/4},{1/4},{1/4},{1/4}}
local matNew = {}
local matHistory = {}
table.insert(matHistory, matOld)
for i = 1, 15 do
matOld = matHistory[i]
matNew = mtx.product(matT, matOld)
if (i < 5) or (i==14) then
context("${\\mathbf P_{"..tostring(i).."} = }$")
mtx.typeset(matT)context("\\times")mtx.typeset(matOld)
context(" = ") mtx.typeset(matNew) context("\\blank")
end
table.insert(matHistory, matNew)
end
table.save("tempList.lua", matHistory)
\stopluacode
\startplacefigure[reference=fig:PR,title={PageRank 값의 변화}]
{\startMPcode
numeric u, yy; u := 1cm;
pair A[];
path p;
string prob;
color myColor[];
myColor[1] := .7red;
myColor[2] := .7blue;
myColor[3] := .7green;
myColor[4] := .7white;
lua("MP = { } MP.data = table.load('tempList.lua')") ;
for j = 1 upto 4:
for i = 1 upto 15:
yy := lua("mp.print(MP.data[" & decimal i & "][" & decimal j & "])");
A[i] := (i*.7u,yy*15u);
% message(lua("mp.print(MP.data[" & decimal i & "][1])"));
endfor;
p := for i = 1 upto 14 : A[i] -- endfor A[15] ;
prob := substring (0,6) of (decimal yy);
label.rt(textext(char(64+j) & " " & prob),A[15]);
draw p withpen pencircle scaled 1.5pt withcolor myColor[j];
drawpoints p;%[i];
endfor;
\stopMPcode}
\stopplacefigure___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the
Wiki!
maillist : [email protected] /
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive : https://github.com/contextgarden/context
wiki : https://wiki.contextgarden.net
___________________________________________________________________________________