Matrix-exponentiation operator: Difference between revisions

m
(→‎{{header|R}}: Syntax highlighting.)
Line 2,939:
Error in mat %*% (mat %^% (n - 1)) : non-conformable arguments</pre>
Our code is far from efficient and could do with more error-checking, but it demonstrates the principle. If we wanted to do this properly, we'd use a library - ideally one that calls C code. Following the previous submission's example, we can just do this:
<lang rrsplus>library(Biodem)
`%^%`<-function(mat,n) Biodem::mtx.exp(mat,n)</lang>
And it will work just the same, except for being much faster and throwing an error on nonSquareMatrix%^%1.
331

edits