Calculate derivative of erfcx(x) function
Show older comments
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.
6 Comments
madhan ravi
on 8 Feb 2019
I suspect there is no analytical derivative for erfcx(x) therefore why not approximate it numerically?
Kevin Frey
on 8 Feb 2019
Bjorn Gustavsson
on 8 Feb 2019
HUH? No analytical derivative of erfcx?
Try:
help erfcx
help erfc
help erf
Then apply the definition of erf in producing a version of erfcx that the symbolic toolbox can handle.
madhan ravi
on 8 Feb 2019
Without transforming erfcx() is it possible to differentiate it?
Kevin Frey
on 8 Feb 2019
Edited: Kevin Frey
on 8 Feb 2019
Bjorn Gustavsson
on 8 Feb 2019
Why cant you do that and plug it into the symbolic differentiation? (It took me ~5 minutes to get an analytical derivative...)
Accepted Answer
More Answers (1)
Bjorn Gustavsson
on 8 Feb 2019
0 votes
Just plug in the definitions of the erfcx function into your symbolic calculations? Or do the differentiation by hand?
HTH
5 Comments
Kevin Frey
on 8 Feb 2019
Steven Lord
on 8 Feb 2019
If you're performing the calculations symbolically (which you will need to do to take the derivative using diff) this isn't a problem. Just don't try to evaluate your result for a large numeric value (or if you do, convert that number into a sym first so you perform the calculation using variable precision arithmetic.)
Bjorn Gustavsson
on 8 Feb 2019
Perhaps. You asked for an analytical derivative in the original post. For symbolic calculations you will not have problems with numerical underflow nor overflow. So I assumed that something like an anlytical derivative would be what you wanted for some purpose or the other, and suggested a simpe 2-3-step way to get you that. If you want a numerical derivative then simly use the gradient function for that.
Kevin Frey
on 8 Feb 2019
Edited: Kevin Frey
on 8 Feb 2019
Bjorn Gustavsson
on 8 Feb 2019
If I got the definitions right you should just simply have expressed erfcx in terms of exp(x^2) and erf:
syms x
diff(exp(x^2)*(1-erf(x)),x)
ans =
- 2/pi^(1/2) - 2*x*exp(x^2)*(erf(x) - 1)
HTH
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!