1. WARNING !!

Euphoria digest :

In case any of you are considering receiving the list in digested mode or are
already doing so, I advise you from the bottom of my heart to AVOID IT even if
it means lots of silly (or not-so-silly) mails in your inBox. It seems that
every time I post a message the digest processor messes up for the next few
days so I never see any replies. If I appear to have been very rude to anybody
this is probably why.

Included is a matrix multiplication prog that I wrote as part of my Maths
revision. I am sure this has been done many times before, but in case you want
it, here it is.

Use it like this :
eg

[ 1 2 3 ]    [ 9 ]
[ 4 5 6 ] x [ 6 ]
[ 7 8 9 ]    [ 3 ]

include matrix.e
sequence result
result=matimult( {{1,2,3},{4,5,6},{7,8,9}} , {{9,6,3}} )
NB even for a one-column matrix you still need two sets of {}s

--------- Start of Code (matrix.e)
type matrix(sequence m)
    atom r,aleng
    sequence len,temp
    r=1
    len={}
    if sequence(m) then
        for a=1 to length(m) do
            if not sequence(m[a]) then
                r=0
                exit
            else
                temp=m[a]
                aleng=length(temp)
                len=len&aleng
                for b=1 to aleng do
                    if sequence(temp[b]) then
                        r=0
                        exit
                    end if
                end for
            end if
        if r=0 then
            exit
        end if
        end for
    else r=0
    end if
    return r
end type

function matimult(matrix m1,matrix m2)
    sequence r
    atom this
    this=0
    if not(length(m1[1])=length(m2)) then
        r={0}  --If not multiplyable return {0}
    else
        r=repeat(repeat(0,length(m2[1])),length(m1))
        for a=1 to length(m2[1]) do --no. columns in m2
            for b=1 to length(m1) do --no. rows in m1
                for c=1 to length(m1[1]) do --no. columns in m1
                    this=this+(m1[b][c]*m2[c][a])
                end for
                r[b][a]=this
                this=0
            end for
        end for
    end if
    return r
end function
------End of Code

Code written by D. Johnson rewrite and distribute as you please. Please give
me credit if used in any product.

Daniel Johnson, Les Mailles Telesoft, Coventry, England

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu