substituting function in diff



I'm not sure I understand your whole problem, but have you taken a look at
substpart?

You can do things like

substinpart( myfavoritefunction( piece ) , expr, 2, 2, 1 )

which extracts inpart(expr,2,2,1), calls your function on it, and returns an
expression with the value in place of the original subexpression.

On Tue, Jul 14, 2009 at 7:51 AM, David Webb <david.webb at noc.soton.ac.uk>wrote:

> 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.
>
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>