I am working on a 2-d wave problem and am trying to write a general function
which will replace expressions of the form:
z^2 * diff(wv(x,y,z,t),z,2) + ... + ...
by a fourier integral equivalent:
ht(kx1,ky1,t)*ht(kx2,ky2,t)*diff(wv(kx3,ky3,t)*g(kx3,ky3,z),z,2)
there being in implicit integral over kx1, ky1 etc. which I deal with later.
In practice there are also terms like diff(diff(wv(x,y,z,t),x,1),z,2) (stored
as [derivative, [wv, x, y, z, t] x, 1, z, 2]), and at(...) operators. The
function also has to deal with "+", "*", "/" and "^" operators.
I have been able to make use of the 'inpart' operator to unpick expressions
but have not found the equivalent reverse operator. Thus with the 'diff'
operator, I can process its first element to get the above
wv(kx3,ky3,t)*g(kx3,ky3,z) but then I have to count the number of additional
parameters and repeat using the 'diff' operator with each pair.
Instead of having to reconstruct each mathematical expression from scratch
using the new terms, it would be more elegant to replace the term in the
original expression. I've tried using the 'List' operators to do this, as
for example, the section says that I should be able to use 'cons' with
functions. However when I try this I get an error, as in,
================================
(%i1) inflag : true;
(%o1) true
(%i2) G : diff(f(x,z),z,1);
d
(%o2) -- (f(x, z))
dz
(%i3) H : cons(p(x)*q(z),rest(G));
Attempt to differentiate with respect to a number:
1
================================
It is obviously trying to evaluate (diff, z, 1), the output from 'rest'. I've
tried to use the ' operator to stop this, but it prevents 'rest' being
evaluated and as soon as it is evaluated I get the 'diff' error again.
So there a elegant way of replacing a term in a function which I have missed?
I would prefer not to descend into lisp - but any help will be welcome.
Regards,
David Webb.