[GOODIE] Matrix-raok
Bert Freudenberg
bert at isg.cs.uni-magdeburg.de
Fri Nov 22 09:35:12 UTC 2002
On Fri, 22 Nov 2002 ok at cs.otago.ac.nz wrote:
> from preamble:
>
> "Change Set: Matrix-raok
> Date: 18 October 2002
> Author: Richard A. O'Keefe
How does this compare to the very nice Matrix class in Croquet?
For those who have not seen it, here are some examples:
"Create a new array"
a := Matrix[3, 3] fill: #(1 2 3 4 5 6 7 8 9).
"Access individual elements"
a[1,2].
a[2,1].
"Assign individual elements"
a[3,1] := 42.
a[1,3] := 21.
"Access vectors"
a[1].
a[1,#all].
a[#all,1].
"Assign vectors"
a[1] := #(-1 -2 -3). a.
a[1,#all] := #(-3 -4 -5). a.
a[#all,1] := #(-6 -7 -8). a.
"Access sub-arrays"
a[(1 to: 2),(1 to: 2)].
a[(2 to: 3),(2 to: 3)].
"Assign sub-arrays"
a[(1 to: 2),(1 to: 2)] := Matrix[2, 2] fill: 1.
a[(2 to: 3),(2 to: 3)] := Matrix[2, 2] fill: 2.
a[#all,#all].
a[#all].
"**** Dave''s examples ***"
"Matrix addition"
m1 := Matrix[3, 3] fill: #(1 2 3 4).
m2 := Matrix[3, 3] fill: #(10 20 30).
m3 := Matrix[3, 3] define: [:i1 :i2 | m1[i1, i2] + m2[i1, i2]].
"Matrix Transpose"
Matrix shape: (m3 matrixShape reverse) define:[:i1 :i2 | m3[i2, i1]].
"Matrix Multiplication (matrix product):"
m1 := Matrix[4, 3] fill: #(1 2 3 4 5 6 7).
m2 := Matrix[3, 2] fill: #(10 20 30 40).
m3 := Matrix[4, 2] define:[ :i1 : i2 | m1[i1,#all ] dot: m2[#all, i2]].
"Laplace filter"
lap := Matrix[3,3] fill: #(1 4 1 4 -20 4 1 4 1).
image := Matrix[50,50] fill: 1.
fImage := Matrix[50,50] define:[:i1 :i2|
(image[(i1-1 to: i1+1), (i2-1 to: i2+1)] * lap) sum sum].
image := Matrix[53,53] fill: 1.
fImage := Matrix[50,50] define:[:i1 :i2|
(i1 at i2) printString displayAt: 0 at 0.
(image[(i1 to: i1+2), (i2 to: i2+2)] * lap) sum sum].
-- Bert
More information about the Squeak-dev
mailing list
|