4
if SearchText(`Release 3`,interface(version))<>0 then
7
readshare(macrofor,numerics):
8
elif SearchText(`Release 4`,interface(version))<>0 then
10
readshare(macrofor,numerics):
12
ERROR(`Unknown Release`)
17
#----------------------------------------------------------------------------
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
#-----------------------------------------------------------------------------
29
addnotations:=proc(varlist)
35
cat(lhs(x),`d`)=cat(`\\dot{`,rhs(x),`}`),
36
cat(lhs(x),`dd`)=cat(`\\ddot{`,rhs(x),`}`)}
41
sortieinit:=proc(filename)
46
sorties:=proc(filename,comment,exp)
54
sortiesI:=proc(filename,comment)
60
sortiesM:=proc(filename,comment,expr)
64
map(x -> mtex(x,latex),expr);
69
sortieinit(`systeme.tex`);
71
#---------------------------------------------------------------
72
# functions for computing euler equations
74
# q,qd,qdd are the state vector and its derivatives
75
#---------------------------------------------------------------
78
euler_equations:=proc(L,q,qd,qdd)
83
v[i,1]:=LL(q[i])=simplify(time_diff(diff(L,qd[i]),q,qd,qdd)
89
#---------------------------------------------------------------
90
# Time derivative computation of an expression
91
# depending on q,qd,qdd
92
# used to compute Euler equations
93
#---------------------------------------------------------------
97
then cat(op(0,xx),`d`)[op(xx)]
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
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)]),
111
diff_phi:=subs(map(xx->xx(t)=xx,[op(q),op(qd),op(qdd)]),diff_phi):
115
#-----------------------------------------------------
116
# Rewritting the Euler equations to have a canonical form
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
#-----------------------------------------------------
123
CEuler:=proc(E,q,qd,qdd)
127
Re:=RRE(E,Me,Ce,q,qd,qdd):
128
[eval(Me),eval(Ce),eval(Re)]:
131
MME:=proc(E,q,qd,qdd)
134
genmatrix([seq(E1[i,1],i=1..nops(qdd))],qdd):
137
#-----------------------------------------------------
138
# extract the CE(q) matrix El= ME(q) qdd + CE(q) qd^2 + RE(q)
139
#-----------------------------------------------------
141
if type(xx,`indexed`)
142
then cat(op(0,xx),`2`)[op(xx)]
146
CCE:=proc(E,q,qd,qdd)
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);
154
#-----------------------------------------------------
155
# extract the RE(q) matrix El= ME(q) qdd + CE(q) qd^2 + RE(q)
156
#-----------------------------------------------------
158
RRE:=proc(E,ME,CE,q,qd,qdd)
161
matadd(multiply(ME,matrix(nops(q),1,qdd)),
162
multiply(CE,matrix(nops(q),1,map(x->x**2,qd)))),
164
MM:=map((x)-> simplify(x),eval(MM)):
168
#-----------------------------------------------------
170
#-----------------------------------------------------
172
Gener:=proc(filename,fortranlist)