Invert non-symmetric tridiagonal Matrix in MatLab

In summary, the conversation discusses the issue of inverting a non-symmetrical tri-diagonal matrix in Matlab and multiplying it with another matrix. The matrix has a size of 1001x1001 and contains values of -0.0096 and 1.0192. The attempts to use the inv() and the backslash operator to solve the issue result in errors due to the matrix being singular. The conversation also touches upon the idea of calculating only the three diagonals around the main diagonal or setting elements to zero when they become too small. Additionally, there is discussion about the structure of the matrix and its determinant and trace. The conversation ends with the suggestion to consider the possibility of using a program that can do exact rational arithmetic to
  • #1
Huibert
6
0
I tried to invert a non-symmetrical tri-diagonal matrix 'ML' in Matlab, and multiply it with matrix 'MR': y = inv(ML)*MR.

size(ML) = 1001 x 1001

Below the end of the matrix is shown, to give an idea of the magnitude of the values:

Code:
   -0.0096    1.0192   -0.0096         0         0
         0   -0.0096    1.0192   -0.0096         0
         0         0   -0.0096    1.0192   -0.0096
         0         0         0         0    1.0000

Calculating inv(ML) results in a 1001x1001 matrix with values NaN.
So I tried (ML)\(MR), but that gives error: "Matrix is singular, close to singular or badly scaled. Results may be inaccurate. RCOND = NaN."

Inverting a almost similar symmetrical tri-diagonal matrix is no problem.

So is it possible to do this inversion?
I would be really grateful with some help!

Huibert
 
Physics news on Phys.org
  • #2
It seems that the problem is not that the matrix is not symmetrical, but that you have zeros in the main diagonal. This makes the determinant zero and the matrix ix consequently singular.
 
  • #3
To see if I could get an idea of what the problem might be, I performed a numerical experiment. I created a 10x10 matrix with structure similar to yours and calculated the determinant to see if it was very small.

I then placed a zero on the main diagonal and recalculated the determinant. It did not become zero. When you have a diagonal matrix with non-zero values only on the main diagonal, then a zero on the diagonal will make the matrix singular, but this doesn't necessarily happen with a tridiagonal matrix.

I then created the same matrix, but with exact rational elements rather than floating point values. After inverting it and displaying the inverse, I can see a pattern in the way the exponents of the elements of the inverse are varying. I think that a 1001x1001 matrix will have an inverse whose elements will have such large negative exponents that the floating point system in Matlab may not be able to cope; I think that's your problem.

If you absolutely must invert your 1001x1001 matrix, you may have to use a program such as Maple or Mathematica that can do exact rational arithmetic, and even then it's probably going to give some elements with integers of perhaps 2000 digits in the denominator.

See the attachments:
 

Attachments

  • TriDiag1.png
    TriDiag1.png
    23.2 KB · Views: 1,740
  • TriDiag2.png
    TriDiag2.png
    35 KB · Views: 1,136
  • #4
Thanks for the effort you took to find this out!

As is seen in TriDiag2, the values far from the main diagonal decrease most. The values of the elements on the three diagonals -1, 0 and 1 are not too small.

Perhaps now I do a stupid suggestion, but would it be possible to only calculate the three diagonals around the main (so -1, 0 and 1)?
Or otherwhise, to set elements to zero when they become too small?
 
  • #5
Huibert said:
Thanks for the effort you took to find this out!

As is seen in TriDiag2, the values far from the main diagonal decrease most. The values of the elements on the three diagonals -1, 0 and 1 are not too small.

Perhaps now I do a stupid suggestion, but would it be possible to only calculate the three diagonals around the main (so -1, 0 and 1)?
Or otherwhise, to set elements to zero when they become too small?

Your matrix is upper triangular. So, the determinant is the product of the terms in the diagonal. Since there are zeros on the diagonal, the determinant is zero and the matrx is singular.
 
  • #6
CEL said:
Your matrix is upper triangular. So, the determinant is the product of the terms in the diagonal. Since there are zeros on the diagonal, the determinant is zero and the matrx is singular.

Look again. His matrix is not upper triangular, and there are no zeros on the main diagonal.

The elements on the main diagonal are all 1.0192, except for the element on the corner. There are values of -0.0096 above and below the main diagonal. He has only shown the lower right corner, but I think the implication is that the main diagonal is an extension of what we see.

The OP describes it as a tridiagonal matrix, and it appears to me that it is indeed tridiagonal.
 
  • #7
Huibert said:
Thanks for the effort you took to find this out!

As is seen in TriDiag2, the values far from the main diagonal decrease most. The values of the elements on the three diagonals -1, 0 and 1 are not too small.

Perhaps now I do a stupid suggestion, but would it be possible to only calculate the three diagonals around the main (so -1, 0 and 1)?
Or otherwhise, to set elements to zero when they become too small?

What do you get if you try to calculate the determinant of your matrix ML?

What do you get for the Trace of ML?
 
  • #8
The Electrician said:
Look again. His matrix is not upper triangular, and there are no zeros on the main diagonal.

The elements on the main diagonal are all 1.0192, except for the element on the corner. There are values of -0.0096 above and below the main diagonal. He has only shown the lower right corner, but I think the implication is that the main diagonal is an extension of what we see.

The OP describes it as a tridiagonal matrix, and it appears to me that it is indeed tridiagonal.

Look again! The elements in the main diagonal are -0.0096, with one zero in the fourth element.
Remember, the OP said that it is a non-symmetrical tri-diagonal matrix. The two secondary diagonals are both above the main diagonal and not one on each side, as with a symmetrical matrix.
 
  • #9
CEL said:
Look again! The elements in the main diagonal are -0.0096, with one zero in the fourth element.
Remember, the OP said that it is a non-symmetrical tri-diagonal matrix. The two secondary diagonals are both above the main diagonal and not one on each side, as with a symmetrical matrix.

A matrix with two superdiagonals above the main diagonal is not an unsymmetrical tridiagonal matrix; see:

http://mathworld.wolfram.com/TridiagonalMatrix.html

See:

http://digilander.libero.it/foxes/matrix/convert_unsym_trid_to_sym.pdf

for examples of an unsymmetrical tridiagonal matrix, and a symmetrical tridiagonal matrix.

You are apparently thinking that what the OP has shown:

Code:
   -0.0096    1.0192   -0.0096         0         0
         0   -0.0096    1.0192   -0.0096         0
         0         0   -0.0096    1.0192   -0.0096
         0         0         0         0    1.0000

is from the upper left portion of the 1001 x 1001 matrix he is asking about.
But he said "Below the end of the matrix is shown, to give an idea of the magnitude of the values:"

This is a portion from the end of the matrix (presumably the lower right), not the beginning of the matrix (the upper left).

If this is the lower right corner of the square 1001 x 1001 matrix, then the main diagonal would be as I have shown in red:

Code:
   -0.0096    [COLOR="Red"]1.0192[/COLOR]   -0.0096         0         0
         0   -0.0096    [COLOR="Red"]1.0192[/COLOR]   -0.0096         0
         0         0   -0.0096    [COLOR="Red"]1.0192[/COLOR]   -0.0096
         0         0         0         0    [COLOR="Red"]1.0000[/COLOR]

Perhaps the OP will clarify what he intended.
 
  • #10
Sorry for irregular posting. I've to do different courses at the moment...

Indeed the end of the matrix is shown. As far as I can see, the values on the diagonal can not be zero, because I defined ML as:

Code:
ML  = diag(one * 1.0192,0) + diag(one_1 * -0.0096,-1)+ diag(one_1 * <value>,1)
ML(1,1)  = 1;
ML(1,2)  = 0;
ML(end,end-1)  = 0;
ML(end,end)  = 1;

So that can not be the problem.
For the matter of fact I found the previous part of the code whas not complete. The upper diagonal shouls be in the range of 0.4, as shown below:

Code:
    0.4151         0         0         0         0         0
    1.0192    0.4151         0         0         0         0
   -0.0096    1.0192    0.4152         0         0         0
         0   -0.0096    1.0192    0.4153         0         0
         0         0   -0.0096    1.0192    0.4153         0
         0         0         0   -0.0096    1.0192    0.4154
         0         0         0         0         0    1.0000

Now:
trace(ML) = 510.5808
det(ML) = NaN, so can't be calculated.
 
  • #11
I think your matrix is not as you think it is.

If this is a 1001x1001 matrix with all 1.0192 on the main diagonal except for the (1,1) and (1001,1001) elements which are 1, then clearly the trace of the matrix should be 999*1.0192+2 which is 1020.18. But you have 510.5808.

Perhaps you should display the entire main diagonal of the matrix and scroll through it; something must be wrong.

Your code snippet shows a quantity "<value>" which is involved in creating the superdiagonal. I see values ranging from .4151 to .4154. Since I don't know what <value> is, I can't create a matrix exactly like yours, but I just used .4151 along the entire superdiagonal

I've shown an 8x8 matrix in the first attached image which I think follows your plan.

In the second image, I increased the size to 1001x1001 and calculated the trace and determinant. I didn't get any arithmetic errors, so I don't know why Matlab isn't returning the same result.

As I said, I think you need to display your matrix and scroll around in it to see if it is constructed as you think it is.

Another thing you might do is to change the size of your matrix. You will see that I have a variable called "siz" which I can easily change. If you will run your program with some smaller sizes, say 10x10, 100x100, 200x200, 500x500 and see what you get for the trace and determinant, I can also run those sized for comparison. Also, tell me what that "<value>" construct is doing so I can do the same.
 

Attachments

  • TriDiag1.png
    TriDiag1.png
    5.5 KB · Views: 694
  • TriDiag2.png
    TriDiag2.png
    4.1 KB · Views: 670
  • #12
ah, found it indeed..

the 'value' was calculated by interpolation of a series in an other file, which first column not started at 0 but at 10. Therefore that values were not right, and apparently that gave some problems.

Thanks a lot for your help!
 

1. How do I invert a non-symmetric tridiagonal matrix in MatLab?

To invert a non-symmetric tridiagonal matrix in MatLab, you can use the inv function. This function will calculate the inverse of a given matrix. Simply pass in your non-symmetric tridiagonal matrix as the input and save the result to a new variable.

2. What is a non-symmetric tridiagonal matrix?

A non-symmetric tridiagonal matrix is a matrix that has nonzero elements only on the main diagonal and the two adjacent diagonals. These nonzero elements can take any value and do not have to follow a specific pattern.

3. Can I use the inv function on a non-symmetric tridiagonal matrix?

Yes, the inv function in MatLab can be used on any square matrix, including non-symmetric tridiagonal matrices. It will calculate the inverse of the given matrix, which can then be used for various calculations.

4. Are there any special considerations when inverting a non-symmetric tridiagonal matrix?

Yes, when inverting a non-symmetric tridiagonal matrix, you should be aware that the inverse may not exist if the matrix is singular. This means that the matrix does not have a unique solution and cannot be inverted.

5. How can I check if my inverted non-symmetric tridiagonal matrix is correct?

To check if your inverted non-symmetric tridiagonal matrix is correct, you can multiply the original matrix by the inverse matrix and see if the result is equal to the identity matrix. If it is, then the inversion was successful.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
19K
  • Calculus and Beyond Homework Help
Replies
2
Views
267
  • Calculus and Beyond Homework Help
Replies
4
Views
2K
  • Advanced Physics Homework Help
Replies
1
Views
2K
  • Linear and Abstract Algebra
Replies
12
Views
2K
  • Linear and Abstract Algebra
Replies
4
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
Back
Top