Search code examples
substitutionmaple

How to substitute a function f(x) in an expression involving D(f)(x) in Maple?


In Maple, if we want to replace the function f(x) with f(x)+a*f1(x) in the following expression, we can do

expr:=f(x)+diff(f(x),x);
subs(f(x)=f(x)+a*f1(x),expr);

However, if we want to make the same substitution in this expression

expr:=f(x)+D(V)(f(x))+D(f)(x);

the term D(f)(x) will not be changed. Is there a convenient way to do a substitution in an expression involving D(f)(x) or higher derivatives?


Solution

  • The first of the following two ways may be more what you want. The second way contains a fix-up, to force that a is constant w.r.t x (ie. a(x) does not depend upon x).

    expr:=f(x)+D(V)(f(x))+D(f)(x);
    
                  f(x) + D(V)(f(x)) + D(f)(x)
    
    eval( expr, f=(t->f(t)+a*f1(t)) );
    
          f(x) + a f1(x) + D(V)(f(x) + a f1(x)) + D(f)(x) + a D(f1)(x)
    
    eval( eval(expr,f=f+a*f1), [D(a)(x)=0, a(x)=a] );
    
          f(x) + a f1(x) + D(V)(f(x) + a f1(x)) + D(f)(x) + a D(f1)(x)