Search All of the Math Forum:

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

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

Topic: creating actual eye(N)
Replies: 4   Last Post: Mar 28, 2013 10:41 AM

 Messages: [ Previous | Next ]
 James Tursa Posts: 2,326 Registered: 8/5/09
Re: creating actual eye(N)
Posted: Mar 28, 2013 3:00 AM

"Iman Behmanesh" wrote in message <kj0fqv\$sgv\$1@newscl01ah.mathworks.com>...
> "James Tursa" wrote in message <kj0e4k\$o9n\$1@newscl01ah.mathworks.com>...
> > "Iman Behmanesh" wrote in message <kj0b8m\$gsi\$1@newscl01ah.mathworks.com>...
> > > I have a matrix, matrix A, and want to optimize some of its components. The residuals are each index (A-I) where I is an identity matrix. matrix A's components are 1 at the diagonals and 0 at non-diagonal elements. for example A^30 or A^-30 is still have 1 at the diagonals and 0 at non-diagonals. However when I subtract A from I, the results is not all zeros as I expect it to be! they are around 10^-15 to 10^-16. I can't use int16(eye(N)) because I can't subtract it later from A. Does anyone know how I can creat an Identity matrix that has zero/1 elements up to the power of -30?!
> >
> > Can you post an explicit example? Not really sure what you are asking. It sounds like simple floating point arithmetic errors from your description.
> >
> > James Tursa

>
>
> You are right, it is because Matlab's zero is 2^(-52)~10^-16. I don't know how I can change it. I know If I can change the default eps, I won't see this error.
>
> Example:
> Suppose you have two matrix square A and B, bot 2x2:
> A=[2 -1;-1 8]; B=[5 0;0 8];
>
> do eigen Analysis:
>
> [V D]=eig(A,B);
>
> then normalize V:
>
> for i=1:2
> w=V(:,i)'*B*V(:,i);
> V(:,i)=V(:,i)/sqrt(w);
> end
>
> Now V'*B*V is expected to be I(2) and it is:
> V'*B*V*10^30
>
> ans =
>
> 1.0e+030 *
>
> 1.0000 0.0000
> 0 1.0000
>
> But V'*B*V-I(2) is not zero as it is expected to be:
> (V'*B*V-eye(2))*10^30
>
> ans =
>
> 1.0e+013 *
>
> 0 2.7756
> 0 0
>
> How can I prevent this? How can I get absolute zero for V'*B*V-eye(2)?!

You have expected floating point calculation errors. E.g.,

>> x = V'*B*V
x =
1.0000 0.0000
0 1.0000
>> x(1,2)
ans =
2.7756e-017
>> x(2,1)
ans =
0

So V'*B*V is not exactly the identity, contrary to what you wrote. The clue is that the (1,2) spot displays as 0.0000 indicating that it is non-zero but too small to display in the format used, whereas the (2,1) spot displays as 0 indicating it is in fact exactly zero.

So the whole thing is pretty much as expected, simple floating point calculation inaccuracies. You will have to handle this in your code as appropriate for your application, rather than expecting to get exact answers for floating point calculations.

James Tursa

Date Subject Author
3/27/13 James Tursa
3/28/13 James Tursa
3/28/13 Steven Lord