Search the web
Sign In
New User? Sign Up
win32forth
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Show off your group to the world. Share a photo of your group with us.

Best of Y! Groups

   Check them out and nominate your group.

Messages

  Messages Help
Advanced
matrix multiplication in forth   Message List  
Reply Message #14491 of 14643 |
Re: Re : [win32forth] matrix multiplication in forth

Andrew K. wrote:
> : matrix_product { A[] B[] A*B \ -- } \ leave product array at adr
> 3 0 do
> 3 0 do
> \ using standard Forth inner and outer loop indeces
> \ I and J, do the required summation of 3 products
> \ A(i,k)*B(k,j) and deposit the results at final
> \ array destination [i,j]
> loop
> loop
> ;

Since it is a 3x3 matrix you need 3 levels of do..loops
After some more time I came to the following:

aNew -3x3Matrix.f \ Final source

3 constant rows

: 3x3Allot [ 3 3 * ] literal cells allot ;

Create 3x3Matrix1 \ Create a 3x3 matrix
1 , 2 , 3 , \ And fill them with some values.
-1 , -2 , -3 ,
5 , 6 , 7 ,

Create 3x3Matrix2
10 , 20 , 30 ,
40 , 50 , 60 ,
70 , 80 , 90 ,

Create 3x3Matrix3 3x3Allot \ For the results

: >ColRow ( col row - adr ) >r cells + r> rows * cells + ;

: .3x3M { MatrixAddr -- } \ To see them
Rows 0
do cr
3 0
do MatrixAddr i j >ColRow @ .
loop
loop cr
;

: 3x3m* { MAddr1 MAddr2 MAddr3 -- }
Rows 0
do
Rows 0
do
0 Rows 0
do MAddr1 I K >ColRow @ MAddr2 J I >ColRow @ * +
loop MAddr3 I J >ColRow !
loop
loop
;

cr .( Two 3x3 matrices containing:)
3x3Matrix1 .3x3M
3x3Matrix2 .3x3M

cr .( Then Multiply them and store the result in matrix3 )
3x3Matrix1 3x3Matrix2 3x3Matrix3 3x3m*

3x3Matrix3 .3x3M \ Show the result
\s Jos

\ Output:

Two 3x3 matrices containing:
1 2 3
-1 -2 -3
5 6 7

10 20 30
40 50 60
70 80 90

Then Multiply them and store the result in matrix3
300 360 420
-300 -360 -420
780 960 1140
ok



Sat Nov 21, 2009 10:54 pm

josven2001
Offline Offline
Send Email Send Email

Message #14491 of 14643 |
Expand Messages Author Sort by Date

hi everybody, I'm beginner in forth programming.i want to do a matrix multiplication (3*3) in forth.can anyone help me.thanks...
RAMZI TLIGUE
ramziesstt
Offline Send Email
Nov 19, 2009
2:21 pm

Hi Ramzi, ... Sounds quite serious. What need the matrix contain? Singles doubles or floats? Jos ... From: "RAMZI TLIGUE" <ramziesstt@...> To: "forth...
Jos v.d.Ven
josven2001
Offline Send Email
Nov 19, 2009
6:19 pm

hi, i prefer to begin with single then we can change.i hope that you can help as soon as possible.thanks ________________________________ De : Jos v.d.Ven...
RAMZI TLIGUE
ramziesstt
Offline Send Email
Nov 19, 2009
9:37 pm

Hi Ramzi, ... Changing it would mean redign and start all over again. That is not my favorite aproach! So if you think you will end into floats, then it is...
Jos v.d.Ven
josven2001
Offline Send Email
Nov 20, 2009
5:22 pm

Hi Ramzi, Here follows a first result. The 3x3m* could perhaps be better. aNew -3x3Matrix.f 3 constant rows ... Create 3x3Matrix1 \ Create a 3x3 matrix 1 , 2...
Jos v.d.Ven
josven2001
Offline Send Email
Nov 20, 2009
11:39 pm

Ramzi, do you know the definition of a matrix product? If not, look it up at Wikipedia: http://en.wikipedia.org/wiki/Matrix_multiplication In Win32Forth you...
Andrew K
kr6dd
Offline Send Email
Nov 21, 2009
5:11 am

... Since it is a 3x3 matrix you need 3 levels of do..loops After some more time I came to the following: aNew -3x3Matrix.f \ Final source 3 constant rows ......
Jos v.d.Ven
josven2001
Offline Send Email
Nov 21, 2009
10:54 pm

hi, thanks for responding,there is a problem because i use gforth to compile my forth file to vhdl and not win32. so there is some error in the program like in...
RAMZI TLIGUE
ramziesstt
Offline Send Email
Nov 22, 2009
8:38 am

... Jos ... From: "RAMZI TLIGUE" <ramziesstt@...> To: <win32forth@yahoogroups.com> Sent: Sunday, November 22, 2009 9:38 AM Subject: [win32forth] matrix...
Jos v.d.Ven
josven2001
Offline Send Email
Nov 22, 2009
12:39 pm

... You always need 3 levels of do..loops irregardless of the size of the matrices you are multiplying. Fred [Non-text portions of this message have been...
Fred Schiff
fschiff
Offline Send Email
Nov 24, 2009
9:23 am

... Not true! There has been a long history of research striving to improve matrix multiplication. Many tricks have been discovered, driving the "loop...
Andrew K
kr6dd
Offline Send Email
Nov 24, 2009
5:25 pm
Advanced

Copyright © 2010 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help