Qfunction with unreal argument

hi,
i want to calculate the qfunction value qfunc(x) where x is not a real value instead it is a function of x.
can this be calculated in MATLAB?
for eg
sym x
f=(40*log10(x/7))/4
qfunc(f);
i am getting an error saying "The argument of the Q function must be a real array."
Regards,
Karki

 Accepted Answer

According to the documentation,
Q(x) = 1/2 * erfc(x / sqrt(2))
So for symbolic use I would say
Qfunc = @(x) erfc(x / sqrt(sym(2))) / 2;
then
Qfunc(f)

13 Comments

now it is generating error as -->
Undefined function or method 'erfc' for input arguments of type 'sym'.
erfc is documented for symbolic. Which MATLAB version are you using?
MATLAB 7.12.0(R2011a)
erfc() was introduced in R2011b. You can use the integral form of it instead.
I am done with previous problem but now I got new problem. After series of calculation and simplification I came to following inline function,
f00(L) = sqrt(2.0).*sqrt(pi).*(erf(sqrt(2.0).*sqrt(3.0).*sqrt(1.31e2).*(sqrt((log(L.*(7.837318882787328e15./1.964805411538173e17)).*(-1.31e2./6.075e3))./log(1.0e1)+1.31e2./2.0e2)-1.31e2./1.0e2).*(2.5e1./1.31e2))-1.0).*(6.403354352296725e18./3.602879701896397e18)+7.91e2./1.0e2
here f00 is nothing but an inline function which is a function of L and I have to solve the expression to get the value of L using iteration method like Newton Raphson Method. But when solving it is generating error as
??? Error using ==> inlineeval at 15 Error in inline expression ==> sqrt(2.0).*sqrt(pi).*(erf(sqrt(2.0).*sqrt(3.0).*sqrt(1.31e2).*(sqrt((log(L.*(7.837318882787328e15./1.964805411538173e17)).*(-1.31e2./6.075e3))./log(1.0e1)+1.31e2./2.0e2)-1.31e2./1.0e2).*(2.5e1./1.31e2))-1.0).*(6.403354352296725e18./3.602879701896397e18)+7.91e2./1.0e2
Input must be real and full.
Error in ==> inline.subsref at 27 INLINE_OUT_ = inlineeval(INLINE_INPUTS_, INLINE_OBJ_.inputExpr, INLINE_OBJ_.expr);
I think the parameter inside erf function became complex that's why i am getting this error. If this is the problem then tell me how can i calculate erf of complex number if not then give me any suggestion how can i tackle this problem ? Thanks in advance
L would have to reach 10^31 for the argument to erf() to become complex.
The solution to L is real valued and positive.
Have you let your test L values become 0? That would involve log(0) ...
As I told you before I have to calculate L by using Newton Raphson Iteration method. I will write part of code here, and A is the expression which is the function of L. If you want I can provide my full code which is not longer (only 62 lines).
%solving A using Newton Raphson Method
A= (6403354352296725483*2^(1/2)*pi^(1/2)*(erf((25*2^(1/2)*3^(1/2)*131^(1/2)*((131/200 - (131*log((7837318882787328*L)/196480541153817325))/(6075*log(10)))^(1/2) - 131/100))/131) - 1))/3602879701896396800 + 791/100
f00=inline(A)
f01=inline(diff(A))
L=2 %initial guess
for i=1:inf
y=L
disp('i = ')
disp(i)
L=y-[f00(L)./f01(L)]
if L==y
break
end
end
L=disp(L)
After running I am getting above errors.
f01 and f00 are both negative near L=2, so you are going to project towards 0. There is a very narrow zone just slightly above 0 where the ratio goes negative, but by the time you get near there you are likely to have projected below 0. And f01 is complex for L negative, leading you to complex L. At that point it seems unlikely you would escape from complex values, as the division of complex numbers seldom will give exact real multiples.
It would be better for your purposes if you could constrain your L to be non-negative.
How can I constrain L to a non negative value, because I have to find the value for L and I am using iteration method for solving it. Is there any other method or way so that I can solve A for the value of L ? Actually I am in the middle of my thesis and I am stuck here. If you can help me here it would be great help for me.
Earlier you indicated that you have to use Newton-Raphson; is that not the case? The symbolic toolbox might be able to solve it (note: it might take a bit of time.) The answer is in the range of L = 1E-30
If you do use an iterative method, you could modify it slightly to add
L = max(L, realmin);
after calculating L.
Actually in my paper which I am taking as base paper for my thesis, the writer has mentioned that we can use various fast and efficient numerical root finding methods such as the Newton Raphson Method, Fixed Point Iteration Method to solve it, so I am thinking about Newton Raphson method but if with Newton Raphson method I am getting error then I think I should change the method. The goal is to find the value for L and I think I can use any method.
And what is this symbolic toolbox is all about how can I use it here ? The expression for A has came from above series of calculation and simplification code now can I use this expression with this symbolic toolbox ?
The symbolic toolbox is the tool that allows "sym" and "diff".
Try this:
feval(symengine, 'numeric::solve', A, L)
I used both of your suggestions. After using your first suggestion i.e
L = max(L, realmin)
after calculating L,
I got the answer L= 3.1783e-030
But after using your second suggestion
feval(symengine, 'numeric::solve', A, L)
I got the answer = [ empty sym ]
I think the answer with the first suggestion is right. So I should go with your first suggestion.
Thank you so much !!

Sign in to comment.

More Answers (0)

Categories

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!