The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Alternative solution for NAN
Replies: 11   Last Post: Feb 27, 2013 5:44 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Tony Kittler

Posts: 109
Registered: 2/5/11
Re: Alternative solution for NAN
Posted: Feb 27, 2013 5:44 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Steven_Lord" <> wrote in message <kgldag$ir9$>...
> "Carl S." <> wrote in message
> news:kgkurb$1t8$

> > "Torsten" wrote in message <kgku2t$t2g$>...
> *snip*

> >> The matrix N you get after the while loop is a scalar multiple of the
> >> identity matrix and in general has nothing in common with your original
> >> matrix N. You will have to find out why eig produces NaN values for your
> >> original matrix N. Are you sure all elements of N are finite ? Best
> >> wishes
> >> Torsten.

> >
> > Yes, Torsten, they are finite
> >
> > My goal is to fit means(mu) and standard deviations(N) to Gaussian shape.
> > The codes that I wrote above are from the function ;
> >
> > function res=MultivariateGaussianPDF(x,mu,N)
> > while(det(N) == 0)

> 1) Don't use DET to test for singularity. This matrix:
> A = 1e-10*eye(400);
> has determinant 0 (due to underflow) but it's a scaled identity matrix,
> which is about as well-behaved as you can get. If you _must_ test for
> singularity, check with COND or RCOND.
> 2) Don't test a floating-point number for exact, bit-for-bit equality unless
> you need exact, bit-for-bit equality. Compare with a tolerance instead.

> > N=(1e-10.*randi(1,size(N)))*eye(size(N));
> > end
> >
> > [M,d]=size(x);
> > [U,D]=eig(N); % <=causes NAN problem :((

> Show the group a SMALL matrix N with which you can reproduce this behavior.
> *snip*
> 3) If you have Statistics Toolbox, do one of these functions do what you
> want?
> If not, please explain more _in words not code or equations_ specifically
> what you mean/are trying to do when you say you want to fit means and
> standard deviations to a Gaussian shape.
> --
> Steve Lord
> To contact Technical Support use the Contact Us link on

Thanks Steven and Torsten,
(It is difficult to prepare a small group of matrix N. I am trying to find likelihood of an image. Codes are working for many images, but gives this NAN error for some of them)
I examined all codes again and saw that the error is due to the non-positive definite values of N. So, I wrote that

[U,D]= chol(N);
if D ~= 0 % <= if N not positive definite
positivedefiniteN = topdm(N); %<=topdm converts N to a positive definite matrix
[U,D]= chol(positivedefiniteN );

(For topdm function, the link is

But, the value of D returns zero therefore
returns NAN and inf values, since, inv(D)=inf

I have tried this
nonsingularD = pinv(D);
but nonsingularD is equal to zero, so it does not solve this problem

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.