Search code examples
matlabsymbolic-math

Shift parameter in a Matlab function


Suppose I have defined the symbolic function x -> f(x) in Matlab. How can I define the function x -> f(x+a) starting from f? (here a is a real number)

I have tried g = @(x) f(x+a) but this definition only allows me to find values of g, but not its derivative. When I try to derivative g it says that it doesn't recognize f as a Matlab function.


Solution

  • Your mistake is that you tried to define g as an anonymous function rather than a symbolic function. Instead, try symbolic substitution with subs:

    g = subs(f, x, x + a)