# Can we use sine and cosine on a matrix of any dimension that needed not to be a square matrix?

**URL:** <https://discourse.julialang.org/t/can-we-use-sine-and-cosine-on-a-matrix-of-any-dimension-that-needed-not-to-be-a-square-matrix/73813>\
**Category:** General Usage\
**Tags:** question\
**Created:** [December 30, 2021, 11:37am UTC](https://discourse.julialang.org/t/can-we-use-sine-and-cosine-on-a-matrix-of-any-dimension-that-needed-not-to-be-a-square-matrix/73813 "2021-12-30T11:37:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shivam\_Jha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shivam_jha/32/32303_2.png) [@Shivam\_Jha](https://discourse.julialang.org/u/Shivam_Jha)\
**Post date:** [December 30, 2021, 11:37am UTC](https://discourse.julialang.org/t/can-we-use-sine-and-cosine-on-a-matrix-of-any-dimension-that-needed-not-to-be-a-square-matrix/73813/1 "2021-12-30T11:37:57Z")

</div>

"

A=rand(2,3)  
cos(A) #will create error

"  
what is the alternative to this

---

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [December 30, 2021, 11:44am UTC](https://discourse.julialang.org/t/can-we-use-sine-and-cosine-on-a-matrix-of-any-dimension-that-needed-not-to-be-a-square-matrix/73813/2 "2021-12-30T11:44:21Z")

</div>

`cos(A)` calculates the [matrix cosine](https://en.wikipedia.org/wiki/Trigonometric_functions_of_matrices) of `A`. If you want the cosine of each element, you can use broadcasting with `.` like this:

```julia
A = rand(2,3)
cos.(A)

```
