real power of matrices

11 views (last 30 days)
Dung Chu
Dung Chu on 6 May 2012
Commented: Christine Tobler on 11 Jun 2025
Today I got this strange problem with using mpower with matrices. Here is the code:
>> x = [1 0 0; 0 1 0; 2 3 1];
>> mpower(x, 0.5);
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.480297e-017. >> mpower(x, 0.5) Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.480297e-017.
ans =
1 0 0
0 1 0
0 0 1
I know that square root of x should be [1 0 0; 0 1 0; 1 1.5 1] as:
>> y = [1 0 0; 0 1 0; 1 1.5 1];
>> y ^ 2
ans =
1 0 0
0 1 0
2 3 1
Can anyone explain? I am aware of the singular problem, but still cannot understand the ability of mpower.

Answers (2)

Hari
Hari on 11 Jun 2025
Hi,
I understand that you're trying to compute the square root of a matrix using mpower(x, 0.5) in MATLAB, and you're confused about the warning and unexpected result, especially since you manually verified that a different matrix indeed squares to x.
I assume you're expecting mpower with a fractional exponent to yield a principal matrix square root similar to a matrix y such that y^2 = x.
In order to understand why mpower(x, 0.5) does not return the expected result, and why the warning occurs, you can consider the following:
Step 1: Understand what mpower does
mpower(A, 0.5) computes the principal square root of matrix A, which is defined only for certain matrices, particularly when the matrix is diagonalizable and not singular. MATLAB internally uses an algorithm based on Schur decomposition, which can be sensitive to numerical conditioning.
Step 2: Investigate if the matrix is singular or ill-conditioned
rcond(x)
This returns a very small value (~1e-17), indicating the matrix is nearly singular. That means its eigenvalues are close to zero or the matrix is not diagonalizable, which causes instability in square root computation.Step 3: Understand that mpower(x, 0.5) returns principal root
Your manually constructed matrix y = [1 0 0; 0 1 0; 1 1.5 1] is not the principal square root that mpower is designed to compute, even though y^2 = x holds. This is because matrix square roots are not unique—there are infinitely many.
Step 4: Use sqrtm for general matrix square root
For general square root computation (not just principal one), use "sqrtm":
sqrtm(x)
This function handles a broader class of matrices and returns the principal square root, if it exists. Compare this with your custom y.
Step 5: Verify custom square root manually (optional)
You can verify if your custom matrix is a square root by squaring it, as you did:
y = [1 0 0; 0 1 0; 1 1.5 1];
isequal(round(y^2, 10), x) % Use rounding to avoid numerical errors
Refer to the documentation of "mpower" function here:
Refer to the documentation of "sqrtm" function here:
Hope this helps!
  1 Comment
Stephen23
Stephen23 on 11 Jun 2025
x = [1,0,0; 0,1,0; 2,3,1];
rcond(x)
ans = 0.0625
sqrtm(x)
ans = 3×3
1.0000 0 0 0 1.0000 0 1.0000 1.5000 1.0000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>

Sign in to comment.


Christine Tobler
Christine Tobler on 11 Jun 2025
I'm not seeing the described behavior:
x = [1 0 0; 0 1 0; 2 3 1];
y = mpower(x, 0.5)
y = 3×3
1.0000 0 0 0 1.0000 0 1.0000 1.5000 1.0000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
y*y
ans = 3×3
1 0 0 0 1 0 2 3 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Can you try to rerun the code?
  1 Comment
Christine Tobler
Christine Tobler on 11 Jun 2025
Oh, I see this is a question from 2012 that Hari picked up to answer. Then I don't expect you're still looking at this problem.
Anyway, current MATLAB returns the correct result. No point in digging into whether there was some problem with which x was passed to MATLAB, or some bug around 2012; it works now.

Sign in to comment.

Categories

Find more on Exponents and Logarithms in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!