Matrix-exponentiation operator: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 1,899: | Line 1,899: | ||
[16130531424904581415797907386349, 9969216677189303386214405760200] |
[16130531424904581415797907386349, 9969216677189303386214405760200] |
||
[9969216677189303386214405760200, 6161314747715278029583501626149]</pre> |
[9969216677189303386214405760200, 6161314747715278029583501626149]</pre> |
||
=={{header|Scheme}}== |
|||
For simplicity, the matrix is represented as a list of lists, and no dimension checking occurs. |
|||
<lang scheme> |
|||
(define (row*col row col) |
|||
(apply + (map * row col))) |
|||
(define (multiply-matrix m1 m2) |
|||
(map |
|||
(lambda (row) |
|||
(apply map (lambda col (row*col row col)) |
|||
m2)) |
|||
m1)) |
|||
(define (matrix-expo mat exp) |
|||
(cond ((= exp 1) mat) |
|||
((even? exp) (square-matrix (matrix-expo mat (halve exp)))) |
|||
(else (multiply-matrix mat (matrix-expo mat (dec exp)))))) |
|||
</lang> |
|||
=={{header|Seed7}}== |
=={{header|Seed7}}== |