"Iman Behmanesh" <email@example.com> wrote in message news:firstname.lastname@example.org... > "James Tursa" wrote in message <email@example.com>... >> "Iman Behmanesh" wrote in message >> <firstname.lastname@example.org>... >> > 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.
> 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: