Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


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

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: 17,944
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" <iman.behmanesh@tufts.edu> wrote in message
news: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.


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

http://www.mathworks.com/help/matlab/ref/eps.html

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.

http://matlab.wikia.com/wiki/FAQ

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

*snip*

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

http://www.mathworks.com/help/symbolic/eig.html

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:

https://en.wikipedia.org/wiki/Numerical_analysis

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com




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

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.