nspire で定義した函数を lua から呼び出すための函数を定義する。
今度は m5 の位置も計算する。
ti-basic
Define pyt(x31,vx31,y31,vy31,x41,vx41,y41,vy41,dt1,tol)= Func :Local r34_3,r35_3,r45_3 :Define r34_3=(√((x3-x4)^(2)+(y3-y4)^(2)))^(3) :Define r35_3=(((1)/(5))*√((8*x3+4*x4)^(2)+(8*y3+4*y4)^(2)))^(3) :Define r45_3=(((1)/(5))*√((3*x3+9*x4)^(2)+(3*y3+9*y4)^(2)))^(3) :Return rk23(system(vx3,((−4*(x3-x4))/(r34_3))-((8*x3+4*x4)/(r35_3)),vy3,((−4*(y3-y4))/(r34_3))-((8*y3+4*y4)/(r35_3)),vx4,((3*(x3-x4))/(r34_3))-((3*x3+9*x4)/(r45_3)),vy4,((3*(y3-y4))/(r34_3))-((3*y3+9*y4)/(r45_3))),t,{x3,vx3,y3,vy3,x4,vx4,y4,vy4},{0,dt1},{x31,vx31,y31,vy31,x41,vx41,y41,vy41},dt1,tol) :EndFunc
.lua
-- nspire で定義した函数を lua から呼び出すための函数を定義する。 -- 今度は m5 の位置も計算する。 function pyt(x31, vx31, y31, vy31, x41, vx41, y41, vy41, dt1, tol) var.store("x31", x31); var.store("vx31", vx31); var.store("y31", y31); var.store("vy31", vy31); var.store("x41", x41); var.store("vx41", vx41); var.store("y41", y41); var.store("vy41", vy41); var.store("dt1", dt1); var.store("tol", tol) local temp = math.eval("pyt(x31, vx31, y31, vy31, x41, vx41, y41, vy41, dt1, tol)") return temp[1][2], -- dt2 temp[2][2], -- x32 temp[3][2], -- vx32 temp[4][2], -- y32 temp[5][2], -- vy32 temp[6][2], -- x42 temp[7][2], -- vx42 temp[8][2], -- y42 temp[9][2], -- vy42 -(3 * temp[2][2] + 4 * temp[6][2])/5, -- x52 -(3 * temp[4][2] + 4 * temp[8][2])/5 -- y52 end function on.resize() print(pyt(1, 0, 3, 0, -2, 0, -1, 0, 1/32, 1/1000)) end
コンソールでの実行結果:
0.03125 0.99995312287405 -0.0030002736563619 2.99978490629 -0.013766374071437 -1.9996935599103 0.019613232306432 -0.99995312287398 0.00300027366968 0.99978297420381 -0.99990844547482