Working with some iterative integral equations, I have Gaussian density functions involved therein. Integrating the Gaussian function I obtain the error function. When I take the second integration, Mathematica is not able to provide an analytical expression. Because apparently there is no closed-form expression for the integral of the error function.
Question: Is it possible the tell Mathematica to consider the error function as some given exact expression which is analytically integrable?
For example
$$\mathrm{erf}(x)=\frac{1}{(1+a_1x+a_2x^2+a_3x^3+a_4x^4)^4}$$
for some appropriate constants $a_1$, $a_2$, $a_3$, $a_4$?
Answer
You could unprotect Erf
and redefine it as you like it.
Unprotect[Erf];
(* Here you define the constants and your erf approximation *)
a1=...; etc.
Erf[x_] := 1/(1 + a1 x + a2 x^2 + a3 x^3 + a4 x^4)^4;
(* Here you perform your calculations with the approximate value of erf *)
myComplexCalculation = Erf[x]/2
(* When you are done, clear your definition and reprotect Erf *)
Clear[Erf];
Protect[Erf];
This can be dangerous but, as long as you know what you are doing, it will work.
A more local workaround is to enclose your 'approximate' calculation within a Block
that blocks the definition of Erf
:
Block[ {Erf},
(* Here you define the constants and your erf approximation *)
a1=...; etc.
Erf[x_] := 1/(1 + a1 x + a2 x^2 + a3 x^3 + a4 x^4)^4;
(* Here you perform your calculations with the approximate value of erf *)
myComplexCalculation = Erf[x]/2
]
Is this what you were looking for or was it the actual expression for the approximation?
As a more general approach to temporarily modifying built-in functions within the walls of a scoping construct, you might also want to have a look at the undocumented function InheritedBlock
, described in this post on Stack Overflow. It appears that it will copy all definitions associated with the symbol you want to block, so that you can change, within the block only the part you need to. Basically, while
Block[ {builtinFun},
code redefining builtinFun from scratch
and using the new builtinFun
]
would give you a completely clean symbol for builtinFun
to code from scratch, using
Internal`InheritedBlock[ {builtinFun},
code redefining parts of the inherited builtinFun
and using the modified builtinFun
]
would give you a completely modifiable copy of builtinFun
, so that you can modify only the parts you need to modify.
Comments
Post a Comment