Create the values of a sequence with Lua
Hi, The idea is to fill the array with the sequence defined by p(0) = 0.3 and p(n + 1) = 0.3 + 0.7*p(n) The problem is that I don't really master Lua but I will learn when I have some time! Thanks for your help. Fabrice \starttext \startluacode context.startxtable({"align={middle,lohi},width=2cm,bodyfont=9pt"}) p = {} p[0] = 0.3 for i=0,19 do p[i+1] = 0.3+0.7*p[i]^2 end context.startxrow() for i=0,19 do context.startxcell() context(i) context.stopxcell() context.startxcell() context(i+1) context.stopxcell() context.startxcell() context("%0.8f",p[i] ) context.stopxcell() context.stopxrow() end context.stopxtable() \stopluacode \stoptext
On Mon, 31 Oct 2022, Fabrice Couvreur via ntg-context wrote:
Hi, The idea is to fill the array with the sequence defined by p(0) = 0.3 and p(n + 1) = 0.3 + 0.7*p(n) The problem is that I don't really master Lua but I will learn when I have some time! Thanks for your help. Fabrice
You just need to adjust the order in which you are doing things... \starttext \startluacode context.startxtable({"align={middle,lohi},width=2cm,bodyfont=9pt"}) local p = {} p[0] = 0.3 for i= 0, 19 do context.startxrow() context.startxcell() context(i) context.stopxcell() -- context.startxcell() context(i+1) context.stopxcell() context.startxcell() context("%0.8f", p[i]) context.stopxcell() context.stopxrow() p[i+1] = 0.3 + 0.7*p[i] end context.stopxtable() \stopluacode \stoptext Aditya
participants (2)
-
Aditya Mahajan
-
Fabrice Couvreur