substitute for independent variable in 'diff



On 10/10/2011 08:00 AM, shorne at energetiq.com wrote:
> I'm being driven nuts by something that should be easy...
> 
> I have a simple differential equation that can be
> un-dimensionalized by defining a new timelike variable tau=t/u,
> or t=tau*u  where u is a constant characteristic time.

I have some hacked up code for nondimensionalizing things. I wouldn't
send it to the list because it's not at all robust, but here's the basic
idea and perhaps you can hack up something yourself that suits your
particular purposes.

I create a list of variables called "dvars" which defines the
dimensional variables in terms of the nondimensional variables, and a
list of the nondimensional variables. In your case:

dvars: [t = u*tau];
ndvars: [tau];

Then I define a couple of pattern rules, something like:

matchdeclare(n,integerp,[dimvar1,dimvar2],lambda([x],member(x,map(lhs,dvars))),
[ndvar1,ndvar2], lambda([x],member(x,ndvars)));

Now I define a set of defmatch rules which match diff(dimvar1,dimvar2,n)
and do some work to convert it into
diff(dimvar1,ndvar1)/diff(dimvar2,ndvar2,n) * diff(ndvar1,ndvar2,n)

where here you have to look up which ndvar corresponds to which dimvar
before constructing this expression so it's not complete code but it's
the basic idea.

Then I define a "nondimensionalize" function which first applies this
pattern, and then goes through and simply uses subst to replace the
dimensional vars with the nondimensional vars in cases that are not
inside a diff.

hope that helps