js functions for matricies (See related posts)

//js functions for matricies

function nr(a){
        return a.length
}

function nc(a){
        return a[0].length
}

function sayDimensions(a){
        s=nr(a)+'x'+nc(a)
        return s;
}

function mat2string(a){
        s='';
        s+=''for(vari=0;i<nr(a);i++){s+=''for(varj=0;j<nc(a);j++){s+='
' s+=a[i][j] } } s+='
' return s; } function writeInLine(){ document.write('')for(vari=0;i<arguments.length;i++){document.write('
'+arguments[i])} document.write('
') } function somma(a,b){ c=new Array(nr(a)); for(var k=0;k<nr(a);k++){c[k]=new Array(nc(a))} for(var i=0;i<nr(a);i++){ for(var j=0;j<nc(a);j++){ c[i][j]=a[i][j]+b[i][j] } } return c; } function diff( a, b){ c=new Array(nr(a)); for(var k=0;k<nr(a);k++){c[k]=new Array(nc(a))} for(var i=0;i<nr(a);i++){ for(var j=0;j<nc(a);j++){ c[i][j]=a[i][j]-b[i][j] } } return c; } function pms( m, s){ c=new Array(nr(m)); for(var k=0;k<nr(m);k++){c[k]=new Array(nc(m))} for(var i=0;i<nr(m);i++){ for(var j=0;j<nc(m);j++){ c[i][j]=s*m[i][j] } } return c; } function prodotto(a,b){ c=new Array(nr(a)); for(var k=0;k<nr(a);k++){c[k]=new Array(nc(b))} for(var i=0;i<nr(a);i++){ for(var j=0;j<nc(b);j++){ c[i][j]=0; for(var l=0;l<nr(b);l++){ c[i][j]+=a[i][l]*b[l][j] } } } return c; }

You need to create an account or log in to post comments to this site.


Related Posts