Matrix-exponentiation operator: Difference between revisions
Content added Content deleted
ReeceGoding (talk | contribs) (→{{header|R}}: Syntax highlighting.) |
ReeceGoding (talk | contribs) m (→{{header|R}}) |
||
Line 2,939: | Line 2,939: | ||
Error in mat %*% (mat %^% (n - 1)) : non-conformable arguments</pre> |
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: |
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 |
<lang rsplus>library(Biodem) |
||
`%^%`<-function(mat,n) Biodem::mtx.exp(mat,n)</lang> |
`%^%`<-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. |
And it will work just the same, except for being much faster and throwing an error on nonSquareMatrix%^%1. |