# Symbolic acos( cos(theta) ) does not return theta.

3 visualizzazioni (ultimi 30 giorni)
Stephen Pope il 31 Mar 2023
Risposto: Paul il 31 Mar 2023
While cos(acos(x)) correctly returns x, acos(cos(theta)) does not return theta.
syms theta real
assume( theta >-1 & theta < 1)
a = simplify( acos(cos(theta)) )
a =
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Torsten il 31 Mar 2023
assume( theta >=0 & theta <= pi)

Accedi per commentare.

### Risposta accettata

Walter Roberson il 31 Mar 2023
syms theta real
assume( theta >-1 & theta < 1)
a = simplify( acos(cos(theta)) )
a =
fplot(a, [-1 1])
If the identity holds then you would expect a straight line, not two lines.
But cos(-theta) = cos(theta) so cos(-1) = cos(1) and so acos(cos(-1)) = acos(cos(1)) rather than being able to distinguish -1 and 1
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Più risposte (2)

John D'Errico il 31 Mar 2023
Modificato: John D'Errico il 31 Mar 2023
Is it true, that acos(cos(theta)) ALWAYS returns theta? TRY AN EXAMPLE.
acos(cos(10))
ans = 2.5664
So it is not true. It works the other way of course. at least it is mathematically true.
But the range of acos is [0,pi) for real arguments, so it cannot return a number outside that interval.
fplot(@acos,[-1,1])
And so then acos(cos(theta)) is possibly best written as
abs(pi - mod(theta - pi,2*pi))
At least, that is the best I can find for an approximation.
fplot(@(theta) acos(cos(theta)),[-20,20],'r--')
hold on
fplot(@(theta) abs(pi - mod(theta - pi,2*pi)),[-20,20],'b:')
You can see the curves overlay on top of each other.
We can try syms, but simplify won't find that solution, even if I push it pretty hard, harder than what I did below:
syms T
simplify(acos(cos(T)),'steps',10,'all',true)
ans =
Anyway, the point is, MATLAB will not return the result you expect there, because it is not true.
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Paul il 31 Mar 2023
simplify does provide an option that returns theta:
syms theta real
assume( theta >-1 & theta < 1)
a = simplify( acos(cos(theta)),'IgnoreAnalyticConstraints',true)
a =
θ
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Calculus in Help Center e File Exchange

R2023a

### Community Treasure Hunt

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

Start Hunting!

Translated by