Jump to content

Matrix-exponentiation operator: Difference between revisions

no edit summary
(Added Burlesque)
No edit summary
Line 1,706:
 
Matrix.Show( n )</lang>
=={{header|M2000 Interpreter}}==
<lang M2000 Interpreter>
Module CheckIt {
Class cArray {
a=(,)
Function Power(n as integer){
cArr=This ' create a copy
dim new()
new()=cArr.a ' get a pointer from a to new()
Let cArr.a=new() ' now new() return a copy
cArr.a*=0 ' make zero all elements
link cArr.a to v()
for i=dimension(cArr.a,1,0) to dimension(cArr.a, 1,1) : v(i,i)=1: next i
while n>0
let cArr=cArr*this ' * is the operator "*"
n--
end while
=cArr
}
Operator "*"{
Read cArr
b=cArr.a
if dimension(.a)<>2 or dimension(b)<>2 then Error "Need two 2D arrays "
let a2=dimension(.a,2), b1=dimension(b,1)
if a2<>b1 then Error "Need columns of first array equal to rows of second array"
let a1=dimension(.a,1), b2=dimension(b,2)
let aBase=dimension(.a,1,0)-1, bBase=dimension(b,1,0)-1
let aBase1=dimension(.a,2,0)-1, bBase1=dimension(b,2,0)-1
link .a,b to a(), b() ' change interface for arrays
dim base 1, c(a1, b2)
for i=1 to a1 : let ia=i+abase : for j=1 to b2 : let jb=j+bBase1 : for k=1 to a2
c(i,j)+=a(ia,k+aBase1)*b(k+bBase,jb)
next k : next j : next i
\\ redim to base 0
dim base 0, c(a1, b2)
.a<=c()
}
Module Print {
link .a to v()
for i=dimension(.a,1,0) to dimension(.a, 1,1)
for j=dimension(.a,2,0) to dimension(.a, 2,1)
print v(i,j),: next j: print : next i
}
Class:
\\ this module used as constructor, and not returned to final group (user object in M2000)
Module cArray (r) {
c=r
Dim a(r,c)
For i=0 to r-1 : For j=0 to c-1: Read a(i,j): Next j : Next i
.a<=a()
}
}
Print "matrix():"
P=cArray(2,3,2,2,1)
P.Print
For i=0 to 9
Print "matrix()^"+str$(i,0)+"="
K=P.Power(i)
K.Print
next i
}
Checkit
</lang>
 
{{out}}
<pre style="height:30ex;overflow:scroll">
matrix():
3 2
2 1
matrix()^0=
1 0
0 1
matrix()^1=
3 2
2 1
matrix()^2=
13 8
8 5
matrix()^3=
55 34
34 21
matrix()^4=
233 144
144 89
matrix()^5=
987 610
610 377
matrix()^6=
4181 2584
2584 1597
matrix()^7=
17711 10946
10946 6765
matrix()^8=
75025 46368
46368 28657
matrix()^9=
317811 196418
196418 121393
</pre >
 
 
=={{header|Maple}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.