MATLAB: Calculate derivative of erfcx(x) function

derivatediff()erfcx()MATLABSymbolic Math Toolboxsymbolic toolbox

I want to know how i can calculater the derivative of an erfcx(x) function with the symbolic math toolbox. The following is what i tried so far:
>> syms x real
>> y = erfcx(x)
Undefined function 'erfcx' for input arguments of type 'sym'.
I also tried doing this with an anonymous function:
>> testing = @(x) erfcx(x)
testing =
function_handle with value:
@(x)erfcx(x)
but then i don't know how to use the diff() function, as i don't know what variable i should give: diff(testing(x)) <- instead of this x.

Best Answer

Try
x = 0:0.1:5;
analytical_derivative = -2/sqrt(pi) + 2.*x.*erfcx(x);
numerical_derivative = (erfcx(x+1.0e-6)-erfcx(x))*1e6;
plot(x,analytical_derivative,x,numerical_derivative)
So my guess is that the derivative of erfcx is erfcx'(x) = -2/sqrt(pi) + 2*x*erfcx(x) (and you can easily deduce this result by differentiating exp(x^2)*erfcx(x) using the product rule).