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: creating actual eye(N)
Replies: 4   Last Post: Mar 28, 2013 10:41 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Steven Lord

Posts: 18,038
Registered: 12/7/04
Re: creating actual eye(N)
Posted: Mar 28, 2013 10:41 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Iman Behmanesh" <> wrote in message
> "James Tursa" wrote in message <kj0e4k$o9n$>...
>> "Iman Behmanesh" wrote in message
>> <kj0b8m$gsi$>...

>> > 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.

No, zero in MATLAB is 0. The quantity you described is machine epsilon.

isequal(0, 2^(-52))
isequal(0, eps)
isequal(eps, 2^(-52))

> I don't know how I can change it. I know If I can change the default eps,
> I won't see this error.

You cannot change EPS; it is a property of the floating-point representation
in which numbers are stored by MATLAB. You could use a different floating
point type (single precision instead of double) but that won't solve the
underlying problem the way you think you want to solve it.

I strongly recommend that you read the first question in the Math/Algorithms
section of the newsgroup FAQ and ideally the references to which it links.
If you don't have time to read through Goldberg fully, at least read the
three page Cleve's Corner article.

> 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:

It is expected to be the 2-by-2 identity to within roundoff error, and it
is. Element (1, 2) of the result is about 2e-17.


> How can I prevent this? How can I get absolute zero for V'*B*V-eye(2)?!

Perform the computations using arbitrary precision arithmetic (Symbolic Math
Toolbox) by converting A and B into sym objects. Since the symbolic EIG
function doesn't compute generalized eigenvalues directly, you will need to
rephrase your problem as inv(B)*A*V = V*D:

However, I would suggest that instead of requiring all the elements of that
residual matrix to be "absolute zero" that you make your algorithm robust to
numerical noise like this. There's a whole branch of mathematics that deals
with this sort of thing:

Steve Lord
To contact Technical Support use the Contact Us link on

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.