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

« back to all changes in this revision

Viewing changes to demos/npend/Maple/Euler.map

  • 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
 
# Copyright INRIA
2
 
with(share):
3
 
 
4
 
if SearchText(`Release 3`,interface(version))<>0 then
5
 
        matadd:=add;
6
 
        readshare(tex):
7
 
        readshare(macrofor,numerics):
8
 
elif SearchText(`Release 4`,interface(version))<>0 then
9
 
        readshare(tex,system):
10
 
        readshare(macrofor,numerics):
11
 
else
12
 
  ERROR(`Unknown Release`)
13
 
fi;
14
 
 
15
 
 
16
 
 
17
 
#----------------------------------------------------------------------------
18
 
#     GENERAL PART
19
 
#----------------------------------------------------------------------------
20
 
#----------------------------------------------------------------------------
21
 
# Notation for Tex output 
22
 
# and TeX output routines
23
 
# this routines generates proper derivative notations up to second derivative
24
 
# for a set of variable. The TeX name for the variables is also given
25
 
# Warning this function will detroy previous values of texsub 
26
 
# Ex : addnotations( { x = `x`  , th = `\\theta`, y =`y` } );
27
 
#-----------------------------------------------------------------------------
28
 
 
29
 
addnotations:=proc(varlist)
30
 
        global texsub;
31
 
        local x,nots:
32
 
        nots:={};
33
 
        for x in varlist do
34
 
                nots:={op(nots),x, 
35
 
                        cat(lhs(x),`d`)=cat(`\\dot{`,rhs(x),`}`),
36
 
                        cat(lhs(x),`dd`)=cat(`\\ddot{`,rhs(x),`}`)}
37
 
        od;
38
 
        texsub:=nots
39
 
end:
40
 
 
41
 
sortieinit:=proc(filename)
42
 
        writeto(filename);
43
 
        writeto(terminal);
44
 
end:
45
 
 
46
 
sorties:=proc(filename,comment,exp)
47
 
        appendto(filename);
48
 
        lprint(comment);
49
 
        lprint(` `);
50
 
        mtex(exp,latex);
51
 
        writeto(terminal);
52
 
end:
53
 
 
54
 
sortiesI:=proc(filename,comment)
55
 
        appendto(filename);
56
 
        lprint(comment);
57
 
        writeto(terminal);
58
 
end:
59
 
 
60
 
sortiesM:=proc(filename,comment,expr)
61
 
        appendto(filename);
62
 
        lprint(comment);
63
 
        lprint(` `);
64
 
        map(x -> mtex(x,latex),expr);
65
 
        writeto(terminal);
66
 
end:
67
 
 
68
 
texwid:=120;
69
 
sortieinit(`systeme.tex`);
70
 
 
71
 
#---------------------------------------------------------------
72
 
# functions for computing euler equations 
73
 
# L : the Lagrangian,
74
 
# q,qd,qdd are the state vector and its derivatives
75
 
#---------------------------------------------------------------
76
 
with(`linalg`):
77
 
 
78
 
euler_equations:=proc(L,q,qd,qdd)
79
 
        local k,m:
80
 
        m:=nops(q);
81
 
        v:=matrix(m,1,0);
82
 
        for i to m  do  
83
 
           v[i,1]:=LL(q[i])=simplify(time_diff(diff(L,qd[i]),q,qd,qdd)
84
 
                                -diff(L,q[i]));
85
 
        od;
86
 
        eval(v):
87
 
        end:
88
 
 
89
 
#---------------------------------------------------------------
90
 
# Time derivative computation of an expression 
91
 
# depending on q,qd,qdd 
92
 
# used to compute Euler equations 
93
 
#---------------------------------------------------------------
94
 
 
95
 
        ttvar:=proc(xx)
96
 
                if type(xx,`indexed`) 
97
 
                then cat(op(0,xx),`d`)[op(xx)]
98
 
                else cat(xx,`d`) fi
99
 
        end:
100
 
 
101
 
 
102
 
time_diff:=proc(phi,q,qd,qdd)
103
 
        local phi_copy,k,ttvar,diff_phi:
104
 
        # subtitution to specify that q,qd ,qdd depends on time 
105
 
        phi_copy:=phi:
106
 
        phi_copy:=subs(map( xx-> xx=xx(t),[op(q),op(qd)]),phi_copy):
107
 
        diff_phi:=diff(phi_copy,t):
108
 
        # subtitution to come back to our variables 
109
 
        diff_phi:=subs(map(xx->diff(xx(t),t)=ttvar(xx),[op(q),op(qd)]),
110
 
                        diff_phi):
111
 
        diff_phi:=subs(map(xx->xx(t)=xx,[op(q),op(qd),op(qdd)]),diff_phi):
112
 
end:
113
 
 
114
 
 
115
 
#-----------------------------------------------------
116
 
# Rewritting the Euler equations to have a canonical form 
117
 
#           ..         .
118
 
# El= ME(q)  q + CE(q) q^2 + RE(q)
119
 
# Computation of ME,CE,RE 
120
 
# CEuler returns a list [ME,CE,RE];
121
 
#-----------------------------------------------------
122
 
 
123
 
CEuler:=proc(E,q,qd,qdd)
124
 
        local Me,Ce,Re:
125
 
        Me:=MME(E,q,qd,qdd):
126
 
        Ce:=CCE(E,q,qd,qdd):
127
 
        Re:=RRE(E,Me,Ce,q,qd,qdd):
128
 
        [eval(Me),eval(Ce),eval(Re)]:
129
 
        end:
130
 
 
131
 
MME:=proc(E,q,qd,qdd)
132
 
        local E1:
133
 
        E1:=eval(E):
134
 
        genmatrix([seq(E1[i,1],i=1..nops(qdd))],qdd):
135
 
        end:
136
 
 
137
 
#-----------------------------------------------------
138
 
# extract the CE(q) matrix  El= ME(q)  qdd + CE(q) qd^2 + RE(q)
139
 
#-----------------------------------------------------
140
 
        ttvarp:=proc(xx)
141
 
                if type(xx,`indexed`) 
142
 
                then cat(op(0,xx),`2`)[op(xx)]
143
 
                else cat(xx,`2`) fi
144
 
        end:
145
 
 
146
 
CCE:=proc(E,q,qd,qdd)
147
 
        local E_copy,q2d:
148
 
        E_copy:=eval(E):
149
 
        q2d:= map(x-> ttvarp(x),qd): 
150
 
        E_copy:=subs( map(x-> x**2=ttvarp(x),qd),eval(E_copy));
151
 
        genmatrix([seq(E_copy[i,1],i=1..nops(qd))],q2d);
152
 
        end:
153
 
 
154
 
#-----------------------------------------------------
155
 
# extract the RE(q) matrix  El= ME(q)  qdd + CE(q) qd^2 + RE(q)
156
 
#-----------------------------------------------------
157
 
 
158
 
RRE:=proc(E,ME,CE,q,qd,qdd)
159
 
        local MM:
160
 
        MM:=matadd(     E,
161
 
                matadd(multiply(ME,matrix(nops(q),1,qdd)),
162
 
                multiply(CE,matrix(nops(q),1,map(x->x**2,qd)))),
163
 
                1,-1);
164
 
        MM:=map((x)-> simplify(x),eval(MM)):
165
 
        end:
166
 
 
167
 
#
168
 
#-----------------------------------------------------
169
 
# FORTRAN GENERATION 
170
 
#-----------------------------------------------------
171
 
 
172
 
Gener:=proc(filename,fortranlist)
173
 
        global optimized;
174
 
        init_genfor();
175
 
        optimized:=true:
176
 
        writeto(filename):
177
 
        genfor(flist):
178
 
        writeto(terminal):
179
 
        end:
180