Computing matrix trigonometric functions with GPUs through Matlab

  • Pedro Alonso
  • Jesús Peinado
  • Javier Ibáñez
  • Jorge Sastre
  • Emilio Defez


This paper presents an implementation of one of the most up-to-day algorithms proposed to compute the matrix trigonometric functions sine and cosine. The method used is based on Taylor series approximations which intensively uses matrix multiplications. To accelerate matrix products, our application can use from one to four NVIDIA GPUs by using the NVIDIA cublas and cublasXt libraries. The application, implemented in C++, can be used from the Matlab command line thanks to the mex files provided. We experimentally assess our implementation in modern and very high-performance NVIDIA GPUs.


Matrix trigonometric functions Matrix cosine Matrix sine GPU computing MATLAB mex MATLAB 



This work has been supported by Spanish Ministerio de Economía y Competitividad and the European Regional Development Fund (ERDF) Grants TIN2014-59294-P and TEC2015-67387-C4-1-R.


  1. 1.
    Serbin SM (1979) Rational approximations of trigonometric matrices with application to second-order systems of differential equations. Appl Math Comput 5(1):75–92MathSciNetCrossRefMATHGoogle Scholar
  2. 2.
    Serbin Steven M, Blalock Sybil A (1980) An algorithm for computing the matrix cosine. SIAM J Sci Stat Comput 1(2):198–204MathSciNetCrossRefMATHGoogle Scholar
  3. 3.
    Hargreaves GI, Higham NJ (2005) Efficient algorithms for the matrix cosine and sine. Numer Algorithms 40:383–400MathSciNetCrossRefMATHGoogle Scholar
  4. 4.
    Al-Mohy Awad H, Higham Nicholas J (2009) A new scaling and squaring algorithm for the matrix exponential. SIAM J Matrix Anal Appl 31(3):970–989MathSciNetCrossRefMATHGoogle Scholar
  5. 5.
    Defez E, Sastre J, Ibáñez Javier J, Ruiz Pedro A (2011) Computing matrix functions arising in engineering models with orthogonal matrix polynomials. Math Comput Model 57:1738–1743MathSciNetCrossRefMATHGoogle Scholar
  6. 6.
    Sastre J, Ibáñez J, Ruiz P, Defez E (2013) Efficient computation of the matrix cosine. Appl Math Comput 219:7575–7585MathSciNetMATHGoogle Scholar
  7. 7.
    Al-Mohy Awad H, Higham Nicholas J, Relton Samuel D (2015) New algorithms for computing the matrix sine and cosine separately or simultaneously. SIAM J Sci Comput 37(1):A456–A487MathSciNetCrossRefMATHGoogle Scholar
  8. 8.
    Alonso P, Ibáñez J, Sastre J, Peinado J, Defez E (2017) Efficient and accurate algorithms for computing matrix trigonometric functions. J Comput Appl Math 309(1):325–332MathSciNetCrossRefMATHGoogle Scholar
  9. 9.
    CUBLAS library (2017) Accessed May 2017
  10. 10.
    Alonso Jordá P, Boratto M, Peinado Pinilla J, Ibáñez González JJ, Sastre Martínez J (2014) On the evaluation of matrix polynomials using several GPGPUs. Universitat Politècnica de València, 2014. Accessed Sept 2017
  11. 11.
    Boratto Murilo, Alonso Pedro, Giménez Domingo, Lastovetsky Alexey L (2017) Automatic tuning to performance modelling of matrix polynomials on multicore and multi-gpu systems. J Supercomput 73(1):227–239CrossRefGoogle Scholar
  12. 12.
    Alonso P, Peinado J, Ibáñez J, Sastre J, Defez E (2017) A fast implementation of matrix trigonometric functions sine and cosine. In: Proceedings of the 17th International Conference on Computational and Mathematical Methods in Science and Engineering (CMMSE 2017), pp 51–55, Costa Ballena, Rota, Cadiz (Spain), July 4th–8thGoogle Scholar
  13. 13.
    Sastre Jorge, Ibáñez Javier, Alonso Pedro, Peinado Jesús, Defez Emilio (2017) Two algorithms for computing the matrix cosine function. Appl Math Comput 312:66–77MathSciNetMATHGoogle Scholar
  14. 14.
    Paterson Michael S, Stockmeyer Larry J (1973) On the number of nonscalar multiplications necessary to evaluate polynomials. SIAM J Comput 2(1):60–66MathSciNetCrossRefMATHGoogle Scholar
  15. 15.
    Higham Nicholas J (2008) Functions of matrices: theory and computation. SIAM, PhiladelphiaCrossRefMATHGoogle Scholar
  16. 16.
    Sastre J, Ibáñez Javier J, Defez E, Ruiz Pedro A (2011) Efficient orthogonal matrix polynomial based method for computing matrix exponential. Appl Math Comput 217:6451–6463MathSciNetMATHGoogle Scholar
  17. 17.
    Sastre J, Ibáñez Javier J, Defez E, Ruiz Pedro A (2015) Efficient scaling-squaring Taylor method for computing matrix exponential. SIAM J Sci Comput 37(1):A439–455CrossRefMATHGoogle Scholar
  18. 18.
    Higham NJ, Tisseur F (2000) A block algorithm for matrix 1-norm estimation, with an application to 1-norm pseudospectra. SIAM J Matrix Anal Appl 21:1185–1201MathSciNetCrossRefMATHGoogle Scholar
  19. 19.
    Demmel JW (1987) A counterexample for two conjectures about stability. IEEE Trans Autom Control 32:340–343CrossRefMATHGoogle Scholar
  20. 20.
    Wright Thomas G (2002) EigTool library. Accessed May 2017

Copyright information

© Springer Science+Business Media, LLC, part of Springer Nature 2018

Authors and Affiliations

  1. 1.Depto. de Sistemas Informaticos y ComputaciónUniversitat Politècnica de ValènciaValenciaSpain
  2. 2.Instituto de Instrumentación para Imagen MolecularUniversitat Politècnica de ValènciaValenciaSpain
  3. 3.Instituto de Telecomunicaciones y Aplicaciones Multimedia (iTEAM)Universitat Politècnica de ValènciaValenciaSpain
  4. 4.Instituto de Matemática MultidisciplinarUniversitat Politècnica de ValènciaValenciaSpain

Personalised recommendations