Jump to content

Matrix-exponentiation operator: Difference between revisions

→‎{{header|Scheme}}: Added some missing functions
(→‎{{header|Scheme}}: Fixed scheme implementation)
(→‎{{header|Scheme}}: Added some missing functions)
Line 1,905:
 
<lang scheme>
(define (even? n)
(if (= 0 (remainder n 2))
#t
#f))
 
(define (dec x)
(- x 1))
 
(define (halve x)
(/ x 2))
 
(define (row*col row col)
(apply + (map * row col)))
Line 1,918 ⟶ 1,929:
(define (matrix-expo mat exp)
(cond ((= exp 1) mat)
((even? exp) (square-matrix (matrix-expo mat (/halve exp 2))))
(else (multiply-matrix mat (matrix-expo mat (-dec exp 1))))))
 
 
</lang>
 
Cookies help us deliver our services. By using our services, you agree to our use of cookies.