Prev: How to transfer a VC matrix to matlab workspace and manipulate it under matlab GUI ?
Next: Iimplement a matlab function of two inputs in simulink
From: Christopher on 6 May 2010 23:19 I'm doing a statistics project and when using the erfc, I get a value my professor tells me is wrong. "1-erfc((-.5/sqrt(.01/3))/sqrt(2))/2 = 0" I know that the real value is close to 0, but isn't actually 0. It's something on the order of 2*10^-15 or so. How can I get MatLab to give the the correct value?
From: Walter Roberson on 6 May 2010 23:43 Christopher wrote: > I'm doing a statistics project and when using the erfc, I get a value my > professor tells me is wrong. > "1-erfc((-.5/sqrt(.01/3))/sqrt(2))/2 = 0" > > I know that the real value is close to 0, but isn't actually 0. It's > something on the order of 2*10^-15 or so. > How can I get MatLab to give the the correct value? You are going to have fun with that ;-) The value is about 2*10^(-16), with the erfc evaluating to about 0.999999999999999995292859409860 which is so close to 1 that the difference cannot be represented in double precision. If you expand the erfc to erf, then you could perhaps use the series expansion shown at http://mathworld.wolfram.com/Erf.html (see about 1/5 of the way through the description)
From: Matt Fig on 7 May 2010 00:07 Now that is small. Good luck to you. http://www.wolframalpha.com/input/?i=1-erfc%28%28-.5%2Fsqrt%28.01%2F3%29%29%2Fsqrt%282%29%29%2F2
From: Bruno Luong on 7 May 2010 04:12 "Christopher " <eaglepointrocks(a)aim.com> wrote in message <hs00r9$9qe$1(a)fred.mathworks.com>... > I'm doing a statistics project and when using the erfc, I get a value my professor tells me is wrong. > > "1-erfc((-.5/sqrt(.01/3))/sqrt(2))/2 = 0" > Hint: use the identity 2= erfc(x)+erfc(-x) and transform the lhs to something else. Bruno
From: Peter Perkins on 7 May 2010 08:53
On 5/6/2010 11:19 PM, Christopher wrote: > I'm doing a statistics project and when using the erfc, I get a value my > professor tells me is wrong. > "1-erfc((-.5/sqrt(.01/3))/sqrt(2))/2 = 0" > > I know that the real value is close to 0, but isn't actually 0. It's > something on the order of 2*10^-15 or so. > How can I get MatLab to give the the correct value? Christopher, this is kind of a funny question. Most people start with erf, or with the Gaussian cumulative distribution function, and have a similar computational problem (where the correct result is very small), and then discover erfc. But OK, let's assume you really started with erfc. First, you need to think about double precision arithmetic. Consider this simpler situation: >> x = 1e-18 x = 1.000000000000000e-018 >> y = 1 - (1-x) y = 0 Is this just a display thing? No, y really _is_ exactly zero: >> isequal(y,0) ans = 1 The question you first need to figure out is, why is y zero? Hint: the outer subtraction is not at fault. Next: as a student, you likely have the Symbolic Toolbox, so do this in variable precision arithmetic (which, for your purposes, is cheating): >> vpa('erfc((-.5/sqrt(.01/3))/sqrt(2))/2',32) ans = 0.99999999999999999764642970492981 So the difference between your erfc value and 1, the thing corresponding to (1-x) above, is on the order of 10-18. Now you need to figure out how to compute 1 - erfc(...)/2 without ending up subtracting 1 from 1. It will help to draw a picture of what erfc is (the upper tail of an integral) and what 1-erfc/2 is. You likely also have the Statistics Toolbox. Once you figure out the above, you might draw a picture of what the Gaussian CDF represents, and then try to figure out these lines in the NORMCDF function: z = (x-mu) ./ sigma; p = 0.5 * erfc(-z ./ sqrt(2)); _That's_ the direction most people end up with erfc from. Hope this helps. |