How to compute arccos for a matrix?
Show older comments
I would like to compute the arccos for a matrix. I know when I want to find log(), exp(), and sqrt () for a matrix , we use logm(A), expm(A) and sqrtm(A) where A is a matrix.
I want to find the following:
x=acos(sqrtm(A)\eye(n))
so, Is it correct to compute it like this ? Or we need to use arccosm(sqrtm(A)\eye(n))? Thank you.
2 Comments
Walter Roberson
on 4 Jul 2020
There are no trig matrix functions in MATLAB, except the ones that work element by element.
Omar B.
on 4 Jul 2020
Answers (1)
Walter Roberson
on 5 Jul 2020
It depends what you are trying to calculate.

And so we could potentially generalize that for matrices, there might be some meaning to
arccosm = @(z) 1i * logm(z + sqrtm(z^2 - 1))
I am having difficulty thinking of a context in which there could be physical meaning for this.
If we substitute in 1/sqrtm(A) then
1i*logm(sqrtm(A\eye(n) - 1) + sqrtm(A)\eye(m))
But is there a meaning for this??
11 Comments
Omar B.
on 5 Jul 2020
Walter Roberson
on 5 Jul 2020
Do do want the arccos of each individual element? Or do you need it in some matrix sense?
For example do you definitely need sqrtm() or would sqrt() be appropriate for you?
Omar B.
on 5 Jul 2020
John D'Errico
on 5 Jul 2020
Yes, but the question is, do you need to compute a matrix acos? Or do you really want to compute the element-wise operation, which is what is already offered in MATLAB.
I am in agreement with Walter, as I have never seen this as being useful. Conversely, tools like expm(A) and sqrtm both have significant utility. For example, expm is a useful tool to solve differntial equations systems. And sqrtm is a useful tool in linear algebra.
So, while I could happily agree that an extension for other functions into the domain of matrix arguments might be of minor mathematical interest, is there some real use you have for such a tool?
John D'Errico
on 6 Jul 2020
f(A)=arccos(1/sqrtm(A))/sqrtm(A); %is it correct to write f(A) as I did?
No. In any respect, in MATLAB, the answer is no.
John D'Errico
on 6 Jul 2020
f(A) was not your only mistake. If all you were thinking of is:
f_A = acos(1./sqrtm(A))/sqrtm(A);
thus an element-wise acos, then that is correct, as an element-wise acos. But you are asking about a matrix form of the acos, which is something completely different, as much different as sqrt(A) would be compared to sqrtm(A).
Your second mistake was that you wrote 1/sqrtm(A). This is not correct at all in MATLAB, and will generate an error for a matrix A.
I assume that you just wanted to compute the inverse of the elements of sqrtm(A)? Or are you asking to compute the MATRIX inverse of the equare root of the MATRIX A? Again, these are totally different things.
Thus point is, what is the actual formula you are trying to write here? It is impossible to know how to correct this expression when written incorrectly, since it is becoming ambiguous as to what formula you want to compute.
Can we assume that you do need to compute the matrix square root there? Or is that the square root of the elements of A? You used sqrtm, but did you mean to use it? Or did you not appreciate the dirrerence there?
Then you wrote 1/sqrtm(A). This makes the entire question ambiguous, because I cannot know if you intended to form the inverse of the elements or the inverse of the matrix.
And that leads me to question if you are really asking for the acos of the elements or the acos of the matrix.
Walter Roberson
on 6 Jul 2020
f = acos(inv(sqrtm(A))/sqrtm(A));
Maybe.
Omar B.
on 7 Jul 2020
Walter Roberson
on 7 Jul 2020
f1 = @(x) acos(sqrtm(x)^(-1)) * sqrtm(x)^(-1);
f2 = @(x) acos(sqrtm(x)/eye(size(x,1))) / sqrtm(x);
f3 = @(x) acos(1./sqrt(x)) ./ sqrt(x);
f1(A)
f2(A)
f3(A)
Try them all and decide which one is the right solution for you.
Categories
Find more on Creating and Concatenating Matrices 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!