after following a example , got error

2

1 / d \ 1 2 2

- m |--- x(t)| - - m omega x(t)

2 \ dt / 2

Error, (in Mechanics:-LagrangeEqs) invalid input: subs received subst1, which is not valid for its 1st argument

Error, invalid input: Mechanics:-GeneralSol expects its 1st argument, eqs, to be of type list, but received eqs

Error, invalid input: rhs received sol, which is not valid for its 1st argument, expr

L;

Mechanics := module()

export SetVariables, LagrangeEqs, GeneralSol;

option package;

local subst1, subst2, varN, t;

SetVariables = proc( vars:: list, time )

local i;

t := time;

varN := nops( vars );

subst1 := {};

subst2 := {};

for i from 1 to var N do

subst1 := subst1 union

{vars[i](t) = q[i], diff(vars[i](t), t) = v[i]};

subst2 := subst2 union

{q[i] = vars[i](t), v[i] = diff(vars[i](t), t)};

end do;

print( subst1 );

print( subst2 );

NULL;

end proc;

LagrangeEqs := proc (L)

local i, l1, term1, term2;

l1 := subs(subst1, L):

for i to varN do

term1 := [seq(diff(subs(subst2, diff(l1, v[i])), t), i = 1..varN)]:

term2 := [seq(subs(subst2, diff(l1, q[i])), i = 1..varN)]:

end do;

[ seq(simplify(term1[i]-term2[i]) = 0, i = 1..varN) ];

end proc;

RayleighEqs := proc(L, R)

local i, l1, r1, term1, term2, term3;

l1 := subs( subst1, L ):

r1 := subs( subst1, R ):

for i from 1 to varN do

term1:=[seq(diff(subs(subst2, diff(l1, v[i])), t), i=1..varN)]:

term2:=[seq(subs(subst2, diff(l1, q[i])), i=1..varN)]:

term3:=[seq(subs(subst2, diff(r1, v[i])), i=1..varN)]:

end do:

[ seq(simplify(term1[i]-term2[i]+term3[i]), i=1..varN) ];

end proc;

LagrEqsII := proc( L, Q::list )

local i, l1, term1, term2;

l1 := subs(subst1, L):

for i to varN do

term1 := [seq(diff(subs(subst2, diff(l1, v[i])), t), i = 1 .. varN)]:

term2 := [seq(subs(subst2, diff(l1, q[i])), i = 1 .. varN)]:

end do;

[seq(simplify(term1[i]-term2[i]) = Q[i], i = 1 .. varN)];

end proc;

LagrEqsIII := proc (L, R, Q::list)

local i, l1, r1, term1, term2, term3;

l1 := subs(subst1, L):

r1 := subs(subst1, R):

for i to varN do

term1 := [seq(diff(subs(subst2, diff(l1, v[i])), t), i = 1 .. varN)]:

term2 := [seq(subs(subst2, diff(l1, q[i])), i = 1 .. varN)]:

term3 := [seq(subs(subst2, diff(r1, v[i])), i = 1 .. varN)]:

end do;

[seq(simplify(term1[i]-term2[i]+term3[i]) = Q[i], i = 1 .. varN)];

end proc;

GeneralSol := proc (eqs::list)

local i, initconds, eqs2;

initconds := NULL:

eqs2 := eqs[][]:

for i to varN do

initconds:=VarNames[i](0)=q[i], (D(VarNames[i]))(0)=v[i], initconds:

end do;

dsolve({initconds, eqs2});

end proc;

end module;

with(LibraryTools):

LibLocation := cat("c:\\Temp");

Save(Mechanics, LibLocation);

with(FileTools):

march('list',"c:\\Temp\\Mechanics.lib");

save(Mechanics, "c:\\Temp\\Mechanics.m");

read "c:\\Temp\\Mechanics.m";

with(Mechanics):

SetVariables([x], t);

L := (1/2)*m*diff(x(t), t)^2 - (1/2)*m*omega^2 * x(t)^2;

eqs := LagrangeEqs(L);

sol := GeneralSol( eqs );

X := unapply( rhs(sol), t );