~ubuntu-branches/ubuntu/hoary/scilab/hoary

« back to all changes in this revision

Viewing changes to demos/simulation/npend/macros.sci

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2005-01-09 22:58:21 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050109225821-473xr8vhgugxxx5j
Tags: 3.0-12
changed configure.in to build scilab's own malloc.o, closes: #255869

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
function [n]=np()
 
2
// Return the size  of the Fortran pendulum 
 
3
// Copyright ENPC
 
4
  n=1;
 
5
  n=fort('np',n,1,'i','sort',1);
 
6
endfunction 
 
7
 
 
8
function [ydot]=npend ( t, th)
 
9
// Fortran version 
 
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 /
 
13
  ydot=ones(6,1)
 
14
  ydot=fort('npend',3,1,'i',t,2,'d',th,3,'d',ydot,4,'d','sort',4);
 
15
endfunction 
 
16
 
 
17
function [E]=ener( th)
 
18
  E=0.0;
 
19
  E=fort('ener',th,1,'d',E,2,'d','sort',2);
 
20
endfunction 
 
21
 
 
22
function [ydot]=npend3 ( t, th)
 
23
// Scilab version of the three link pendulum 
 
24
  n=3
 
25
  t1 = -th(3)
 
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))
 
28
  t17 = r(3)**2
 
29
  t25 = 2*r(2)*m(3)*r(3)*cos(th(2)+t1)
 
30
  t26 = r(2)**2
 
31
  t31 = r(1)**2
 
32
  ME3S(1,3) = t7
 
33
  ME3S(2,1) = t16
 
34
  ME3S(1,2) = t16
 
35
  ME3S(3,3) = m(3)*t17+J(3)
 
36
  ME3S(3,2) = t25
 
37
  ME3S(3,1) = t7
 
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)
 
40
  ME3S(2,3) = t25
 
41
  t1 = -th(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)
 
45
  CC3S(1,3) = 2*t6
 
46
  CC3S(2,1) = -2*t15
 
47
  CC3S(1,2) = 2*t15
 
48
  CC3S(3,3) = 0
 
49
  CC3S(3,2) = -2*t22
 
50
  CC3S(3,1) = -2*t6
 
51
  CC3S(2,2) = 0
 
52
  CC3S(1,1) = 0
 
53
  CC3S(2,3) = 2*t22
 
54
  t1 = cos(th(2))
 
55
  t5 = m(3)*g
 
56
  t14 = cos(th(1))
 
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
 
60
 
 
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
 
64
endfunction 
 
65
 
 
66
  
 
67
function [E]=ener3(yt)
 
68
// Scilab version for th three link pendulum 
 
69
  th=yt(1:n);
 
70
  thd=yt((n+1):2*n);
 
71
  t1 = r(1)**2
 
72
  t2 = sin(th(1))
 
73
  t3 = t2**2
 
74
  t4 = thd(1)**2
 
75
  t7 = cos(th(1))
 
76
  t8 = t7**2
 
77
  t16 = r(1)*t2
 
78
  t22 = sin(th(2))
 
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
 
81
  t39 = 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)
 
85
endfunction 
 
86
 
 
87
 
 
88
function []=npend_build_and_load() 
 
89
// since this demo can be run by someone 
 
90
// who has no write access in this directory 
 
91
// we use TMPDIR 
 
92
 
 
93
  if ~c_link('npend') then
 
94
    cd = getcwd(); 
 
95
    chdir(TMPDIR); 
 
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");
 
102
    exec loader.sce 
 
103
    chdir(cd) 
 
104
  end
 
105
endfunction 
 
106