acos
Compute the arc cosine of x
, where the output is in radians.
- For
x
in range[-1, 1]
, return value in range[0, pi]
- Otherwise, throw a
DomainError
Base.acos
— Methodacos(x)
Compute the inverse cosine of x
, where the output is in radians
Methods
julia> methods(acos, (Any,), [Base, Base.Math, Base.MathConstants, Base.MPFR])
# 7 methods for generic function "acos" from Base: [1] acos(a::ComplexF16) @ Base.Math math.jl:1512 [2] acos(::Missing) @ Base.Math math.jl:1533 [3] acos(x::BigFloat) @ Base.MPFR mpfr.jl:860 [4] acos(a::Float16) @ Base.Math math.jl:1511 [5] acos(x::T) where T<:Union{Float32, Float64} @ Base.Math special/trig.jl:671 [6] acos(x::Real) @ Base.Math math.jl:1528 [7] acos(z::Complex) @ complex.jl:952
Examples
julia> using UnicodePlots
julia> lineplot(-1, 1, acos; ylim=(0, pi))
┌────────────────────────────────────────┐ 3.14159 │⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ acos(x) │⠘⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ │⠀⠈⠒⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ │⠀⠀⠀⠈⠑⠦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ │⠀⠀⠀⠀⠀⠀⠈⠑⠦⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠒⠤⣀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠒⠤⣀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ f(x) │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠒⡧⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠉⠓⠦⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠉⠓⠦⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠒⢄⡀⠀⠀⠀⠀⠀⠀│ │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠓⢄⡀⠀⠀⠀│ │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠦⡀⠀│ │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⡆│ 0 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│ └────────────────────────────────────────┘ ⠀-1⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀1⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀x⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
Real Numbers
julia> acos(1.0)
0.0
julia> acos(0.0)
1.5707963267948966
julia> acos(-1.0)
3.141592653589793
julia> acos(2.0)
ERROR: DomainError with 2.0:
acos(x) not defined for |x| > 1
Stacktrace:
[...]
Complex
julia> acos(2.0+0im)
0.0 - 1.3169578969248166im
julia> acos(2.0-0im)
0.0 + 1.3169578969248166im
julia> acos(-2.0+0im)
3.141592653589793 - 1.3169578969248166im
julia> acos(-2.0-0im)
3.141592653589793 + 1.3169578969248166im
Tips
- For real number input, the input range is limited to
[0, 1]
. For larger ranges, use complex inputs. - The output is expressed in radians, and needs to be converted if a degrees is required:
degrees = radians * 180 / pi
See Also
Extended Inputs
Matrix
With Array
like input:
Base.acos
— Methodacos(A::AbstractMatrix)
Compute the inverse matrix cosine of a square matrix A
.
If A
is symmetric or Hermitian, its eigendecomposition (eigen
) is used to compute the inverse cosine. Otherwise, the inverse cosine is determined by using log
and sqrt
. For the theory and logarithmic formulas used to compute this function, see [AH16_1].
Examples
julia> acos(cos([0.5 0.1; -0.2 0.3]))
2×2 Matrix{ComplexF64}:
0.5-8.32667e-17im 0.1+0.0im
-0.2+2.63678e-16im 0.3-3.46945e-16im
julia> methods(acos, (Any,), [LinearAlgebra])
# 5 methods for generic function "acos" from Base: [1] acos(J::UniformScaling) @ LinearAlgebra /opt/hostedtoolcache/julia/1.11.2/x64/share/julia/stdlib/v1.11/LinearAlgebra/src/uniformscaling.jl:173 [2] acos(D::Diagonal) @ LinearAlgebra /opt/hostedtoolcache/julia/1.11.2/x64/share/julia/stdlib/v1.11/LinearAlgebra/src/diagonal.jl:802 [3] acos(A::Hermitian{var"#s5027", S} where {var"#s5027"<:Complex, S<:(AbstractMatrix{<:var"#s5027"})}) @ LinearAlgebra /opt/hostedtoolcache/julia/1.11.2/x64/share/julia/stdlib/v1.11/LinearAlgebra/src/symmetric.jl:743 [4] acos(A::Union{Hermitian{var"#s5028", S}, Symmetric{var"#s5028", S}} where {var"#s5028"<:Real, S}) @ LinearAlgebra /opt/hostedtoolcache/julia/1.11.2/x64/share/julia/stdlib/v1.11/LinearAlgebra/src/symmetric.jl:734 [5] acos(A::AbstractMatrix) @ LinearAlgebra /opt/hostedtoolcache/julia/1.11.2/x64/share/julia/stdlib/v1.11/LinearAlgebra/src/dense.jl:1211
julia> acos([-1 0; 0 -1])
2×2 Matrix{Float64}:
3.14159 0.0
0.0 3.14159
Tech Notes
acos(::Real)
: by pure juliaacos(::BigFloat)
: by MPFR
Version History
Introduced in 2018 (1.0)
External Links
- AH16_1Mary Aprahamian and Nicholas J. Higham, "Matrix Inverse Trigonometric and Inverse Hyperbolic Functions: Theory and Algorithms", MIMS EPrint: 2016.4. https://doi.org/10.1137/16M1057577