2 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
5 // This file is distributed under the same license as the Scilab package.
10 function [res,ires]=pendg(t,y,ydot)
17 res(4) = (M+m)*up(1)+m*l*cos(x(3))*up(3)-m*l*sin(x(3))*u(3).^2+lambda*fx(x(1),x(2))+k*u(1);
18 res(5) = (M+m)*up(2)+m*l*sin(x(3))*up(3)+m*l*cos(x(3))*u(3).^2+(M+m)*g+lambda*fy(x(1),x(2))+k*u(2);
19 res(6) = m*l*cos(x(3))*up(1)+m*l*sin(x(3))*up(2)+m*l^2*up(3)+m*g*sin(x(3));
20 res(7) = -(fx(x(1),x(2))*u(1)+fy(x(1),x(2))*u(2));
26 function H=build_sliding_pendulum ()
28 //build the sliding pendulum figure and graphic objects,
29 //return the handle on moving parts
38 f.axes_size = [610,676] ;
44 a.data_bounds=[xmin ymin;xmax ymax]
48 xrect(xmin,ymax,xmax-xmin,ymax-ymin)
57 //the pendulum segment
61 xp = x+l*sin(teta); yp=y-l*cos(teta);
62 r = 0.05 // the bullet half diameter
63 xp1 = x+(l-r)*sin(teta);
64 yp1 = y-(l-r)*cos(teta);
65 xpoly([x;xp1],[y;yp1],"lines")
69 xfarc(xp-r,yp+r,2*r,2*r,0,360*64)
71 H = glue([p,b]) //return the handle on segment and bullet
75 function draw_sliding_pendulum (H,state)
76 //draw the pendulum in a given state
77 x=state(1); y=state(2); teta=state(3);
78 // bullet half diameter
79 b = H.children(1);r=b.data(3)/2
81 xp=x+l*sin(teta); yp=y-l*cos(teta);
82 xp1=x+(l-r)*sin(teta); yp1=y-(l-r)*cos(teta);
84 p = H.children(2);p.data=[x, y; xp1, yp1];
85 b = H.children(1); b.data=[xp-r,yp+r,2*r,2*r,0,360*64];
88 a.title.text="sliding pendulum, parabola";