ÎÌÌÌ̈ˆˆ¬ªªª¬ˆˆˆ¬ÌÌ̬ÌÀ̬ÌÀ̬ÌÀÌÌÌìÌÀÀî̬ÀÌÀ¬ÀÀÀ¬ÀÀÀ¬ÀÀÎÌÌÌ̈ˆˆ¬ªªª¬ˆˆˆ¬ÌÌ̬ÌÌ̬ÌÀ̬ÌÀÌÌÌìÌÀÀî̬ÀÌ̬ÀÀÀ¬ÀÀÀ¬ÀÀ¬ÌÌ̬ªªª¬ª¬ª¬ªÊ̬ªªªŒˆˆˆÌÀÌÎÌÌÎ̬̪ªÀ쬪ÀÀÀÌîÀìîÌÌîî¬ÌÌ̬ªªª¬ª¬ª¬ªÊ̬ªªªŒˆˆˆÌÀÌÎÌÌÎ̬̪ªÀ쬪ÀÀÀÌîÀìîÌÌîî >À?!!!!!!31331331333UUUUQUQUUQUUUQUQUUUQUQUUQQUUQUUQQUUQQQUUQQUQUQUUUQUQUQQUUUUQUUQUQQUQQUUUUQQQUQQQUQUUUQUUUUQUUQQUUQUUUUQUUQUQUUõ-- title: hamsph00 -- author: fnordomat -- desc: simulation of spherical pendulum -- script: lua -- version: 0002 t=0 -- timestep for simulation d=0.1 -- set initial parameters (m and l are fixed) p={ phi=0.0, theta=1.05, m=10.15, l=25.0, vphi=-0.30, vtheta=0.1 } -- convert speeds to momenta function init(p) p.pmtheta = pmtheta(p) p.pmphi = pmphi(p) p.vphi = nil p.vtheta = nil -- often occurring constant factor p.fac = 1.0/(p.m*p.l^2) end -- to initialize momentum from initial speed function pmtheta(p) return p.m * p.l ^ 2 * p.vtheta end -- to initialize momentum from initial speed function pmphi(p) return p.m * p.l ^ 2 * math.sin(p.theta) ^ 2 * p.vphi end function dtheta(p) return p.fac*p.pmtheta end function dphi(p) return p.fac*p.pmphi/(math.sin(p.theta)^2) end function dpmtheta(p) local sintheta = math.sin(p.theta) return -p.fac*(p.pmphi^2)/ (sintheta^3)* math.cos(p.theta)+ p.m*p.l*9.81*sintheta end function hamilton(p) return p.fac*p.pmtheta^2/2 + p.fac*p.pmphi^2/(2*math.sin(p.theta)^2) - p.m * 9.81 * p.l * math.cos(p.theta) end init(p) -- Integrator: Leapfrog scheme function lf_step(p) p.pmtheta = p.pmtheta + d/2 * dpmtheta(p) p.theta = p.theta - d * dtheta(p) p.phi = p.phi - d * dphi(p) p.pmtheta = p.pmtheta + d/2 * dpmtheta(p) end function TIC() cls(1) local plsintheta = p.l*math.sin(p.theta) x = plsintheta * math.cos(p.phi) y = plsintheta * math.sin(p.phi) z = p.l * (1 - math.cos(p.theta)) line(120, 79 - p.l, 120+x,79 - z, 2) -- always view from a safe distance ;-) size =30/(y+(1.2 * p.l)) circ(120 + x, 79 - z, size, 3) lf_step(p) -- Ekin + Epot should remain constant! print(hamilton(p),84,84,5) t=t+1 end