-- Nspire の組込函数だけでなく Nspire のユーザー定義函数も Lua で利用できる。 -- CAS も Lua で利用できる。 platform.apiLevel = '1.0' local radius = 1 var.store("radius", radius) -- Lua と Nspire とで変数名が同じでもよい。 function on.paint(gc) local ans = {-- 1. 半径 radius の球の体積を普通に計算する。 4/3 * math.pi * radius^3, -- 2. Nspire の組込函数で半径 radius の球の体積を求める。 -- 先に半径を var.store() 函数で Nspire に渡しておく。 math.eval("4/3 * pi * radius^3"), -- 3. 同上。ただし半径も expression と一緒に Nspire へ渡す。 math.eval("(4/3 * pi *"..radius.."^3)"), -- 4. Nspire 側で作ったユーザー定義函数 misc\vol_sph() で半径 radius の球の体積を求める。 math.eval("misc\\vol_sph(radius)"), -- 5. Nspire の integral() 函数で球の体積の公式(厳密解)を求める。 -- pi * (r^2 - x^2) を -r から r まで x で積分する。 -- true オプションを付けると厳密解が求まる。 -- Nspire の string() 函数で文字列に変換してから受け取る。 math.eval("string(integral(pi * (r^2 - x^2), x, -r, r))", true),} for i = 1, #ans do gc:drawString(i..": "..ans[i], 5, i * 20) end end
ハンドへルド・ビュー: