Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.



Re: creating actual eye(N)
Posted:
Mar 28, 2013 10:41 AM


"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 (AI) where I is an identity matrix. >> > matrix A's components are 1 at the diagonals and 0 at nondiagonal >> > elements. for example A^30 or A^30 is still have 1 at the diagonals >> > and 0 at nondiagonals. 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 floatingpoint 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 2by2 identity to within roundoff error, and it is. Element (1, 2) of the result is about 2e17.
*snip*
> How can I prevent this? How can I get absolute zero for V'*B*Veye(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



