# Qfunc and erfc in cvx

Can I use qfunc or erfc in cvx? Whenever I use it, it gives an error "Undefined function ‘erfc’ for input arguments of type ‘cvx’."
Is there any way to manually define the function?

No, there is no way to define either of these functions, sorry. The underlying solvers simply cannot handle them. There is, however, a function `log_normcdf` that you may find useful, that uses a polynomial approximation that is reasonably good for `-4 <= x <= 4`.

A full list of the supported functions is in the documentation.

A. I just wonder why we cannot do that. First of all the q-function can be expressed through the exponential functions as in the Craig expression

Thus since CVX can handle the exponential function, we can do the same for q-function as well.
I think that a few code lines defining the q-function based on the exponential functions can do the trick. Is it true?

B. I mean we can do it like that (my MatLab code)

stepsize = 0.001;
ang = 0:stepsize:(pi/2);
[~,sizea] = size(ang);

Now to compute q function at a value x, we can just do
q_approx = stepsize * 1/pi * sum(exp(-x^2./(2*sin(ang).^2)));

We know that exp(-y) is concave, and the sum of concave functions are concave. So q_approx is concave. Note that exp can be expressed in CVX. Thus we can certain add q_approx to the core of CVX as well. Just need to define a precision parameter to specify stepsize.

No. Remember, CVX cannot support arbitrary combinations of the functions in its function list. All combinations must satisfy the disciplined convex programming ruleset. The Q function cannot be represented in this way.

I mean we can do it like that (my MatLab code): stepsize = 0.001; ang = 0:stepsize:(pi/2); [~,sizea] = size(ang); Now to compute q function at a value x, we can just do: q_approx = stepsize * 1/pi * sum(exp(-x^2./(2*sin(ang).^2)));
The sum of exp(-y) is concave -> can add q func to the core of CVX

I’m afraid you’re just going to have to take my word for it. It can’t be done. You can, however, approximate the function with a convex polynomial, if you like, and use the `polyval` function.