2
// Return the size of the Fortran pendulum
5
n=fort('np',n,1,'i','sort',1);
8
function [ydot]=npend ( t, th)
10
// data r / 1.0, 1.0, 1.0, 1.0 /
11
// data m / 1.0, 1.0, 1.0, 1.0 /
12
// data j / 0.3, 0.3, 0.3, 0.3 /
14
ydot=fort('npend',3,1,'i',t,2,'d',th,3,'d',ydot,4,'d','sort',4);
17
function [E]=ener( th)
19
E=fort('ener',th,1,'d',E,2,'d','sort',2);
22
function [ydot]=npend3 ( t, th)
23
// Scilab version of the three link pendulum
26
t7 = 2*r(1)*m(3)*r(3)*cos(th(1)+t1)
27
t16 = 2*cos(th(1)-th(2))*r(1)*r(2)*(m(2)+2*m(3))
29
t25 = 2*r(2)*m(3)*r(3)*cos(th(2)+t1)
35
ME3S(3,3) = m(3)*t17+J(3)
38
ME3S(2,2) = 4*t26*m(3)+m(2)*t26+J(2)
39
ME3S(1,1) = J(1)+m(1)*t31+4*t31*m(2)+4*t31*m(3)
42
t6 = r(1)*m(3)*r(3)*sin(th(1)+t1)
43
t15 = r(1)*r(2)*sin(th(1)-th(2))*(m(2)+2*m(3))
44
t22 = r(2)*m(3)*r(3)*sin(th(2)+t1)
57
Const(2,1) = m(2)*g*r(2)*t1+2*r(2)*t1*t5
58
Const(3,1) = m(3)*g*r(3)*cos(th(3))
59
Const(1,1) = 2*r(1)*t14*m(2)*g+2*r(1)*t14*t5+m(1)*g*r(1)*t14
61
ydot(1:n,1)=th((n+1):2*n)
62
const= const+ cc3S*( th((n+1):2*n,1).* th((n+1):2*n,1));
63
ydot((n+1):2*n,1)= -me3s\const
67
function [E]=ener3(yt)
68
// Scilab version for th three link pendulum
79
t27 = (-2*r(1)*t2*thd(1)-r(2)*t22*thd(2))**2
80
t35 = (2*r(1)*t7*thd(1)+r(2)*cos(th(2))*thd(2))**2
82
E= m(1)*(t1*t3*t4+t1*t8*t4)/...
83
2+J(1)*t4/2+m(1)*g*t16+m(2)*(t27+t35)/2+...
84
J(2)*t39/2+m(2)*g*(2*t16+r(2)*t22)
88
function []=npend_build_and_load()
89
// since this demo can be run by someone
90
// who has no write access in this directory
93
if ~c_link('npend') then
96
fcode=mgetl(SCI+'/demos/npend/Maple/dlslv.f');mputl(fcode,'dlslv.f')
97
fcode=mgetl(SCI+'/demos/npend/Maple/ener.f');mputl(fcode,'ener.f')
98
fcode=mgetl(SCI+'/demos/npend/Maple/np.f');mputl(fcode,'np.f')
99
fcode=mgetl(SCI+'/demos/npend/Maple/npend.f');mputl(fcode,'npend.f')
100
files = ['npend.o','np.o','ener.o','dlslv.o' ];
101
ilib_for_link(['npend';'np';'ener'],files,[],"f");