[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

LOGO-L> Matrix Movie



;Hello Everybody
;here is a code to display a matrix inversion movie. It will run
;only in UCBLogo.It will not run in MSWLogo (Sorry George !).
;If you want to follow up the movie you can uncomment the wait 1
;statment at the end of invert procedure.
;Invert is a an implementation of Gauss-Jordan elimination method.
;Try to invert the "inverted matrix" just by typing go once more.
;Ofcourse you can change the matrix provided its order is less
;than nine. 
;Enjoy the movie.
;Best regards
;Mhelhefny
;-------------------- 
to display :a :b :c
make "n count :a 
for [i 1 :n][
    for [j 1 :n][
    make "aa mditem se :i :j :a setcursor se :b+ :j*7 :i+ :c 
    type form :aa 7 3 setcursor se 3 5
                ]
            ]
end 

to go
ct    init               setcursor se 3 4      pr [original]
      display :a 5 3     invert :a             setcursor se 3 13 
      pr [inverse]
end

to init
make "a {{1 2 3 4 4 1 3 3}{4 5 6 7 2 3 3 1}{2 2 3 4 1 2 1 2}
         {1 2 5 1 3 1 5 2}{3 0 4 4 6 1 4 1}{4 1 6 5 1 3 .7 3}
         {3 2 5 1 3 3 9 1}{1 4 3 2 1 3 1 1}}
end

to invert :a
make "det 1
for [l 1 :n][
    make "x mditem (se :l :l) :a make "det :det* :x
    ifelse :x = 0 [pr [singular matrix] stop][mdsetitem (se :l :l) :a 1 
      for [j 1 :n 1][
          make "k mditem (se :l :j) :a make "k :k/ :x 
          mdsetitem (se :l :j) :a :k]
          for [i 1 :n][
              ifelse :i=:l [type " ][make "x mditem (se :i :l) :a mdsetitem (se
:i :l) :a 0
                for [j 1 :n][
                make "aa mditem (se :i :j) :a make "bb mditem (se :l :j) :a 
                make "bb :bb* :x make "bb :aa- :bb mdsetitem (se :i :j) :a :bb
                setcursor se 5+ :j*7 12+ :i pr form :bb 7 3 setcursor se 3 5 
                ;wait 1      ]
                            ]
                       ]
                     ]
              ]
display :a 5 12 pr[]
end
;------------------------Z
---------------------------------------------------------------
Please post messages to the Logo forum to logo-l@gsn.org.  Mail
questions about the list administration to logofdn@gsn.org.  To
unsubscribe send    unsubscribe logo-l    to majordomo@gsn.org.



Global SchoolNet Foundation - Linking Kids Around the World!
Copyright GSN - All Rights Reserved - Comments & Questions
Visit GSN's Global Schoolhouse for more exciting learning resources!
Search our Site - Home