Release Matrix Functions
#1
Hello

I was recommended to release this functions, they are part of a math gsc stuff I made sometime ago, I havent made all the stuff I wanted about these, but I got tired and stopped the project, if anyone wants to work with these just go on or if you need help you can ask me Big Grin

Code:
CreateMatrix( matrix ) { files = StrTok( matrix, ";" ); m = []; wait ( 0.05 ); for( i = 0; i < files.size; i ++ ) { columns = StrTok( files[i], "," ); for( j = 0; j < columns.size; j ++ ) m[i][j] = int( columns[j] ); } return m; } getMatrixRows( matrix ) { rows = 0; for( j = 0; j <= 1000; j ++ ) { if( ! isDefined( matrix[j][0] ) ) { rows = ( j ); break; } } return rows; } getMatrixColumns( matrix ) { columns = 0; for( i = 0; i <= 1000; i ++ ) { if( ! isDefined( matrix[0][i] ) ) { columns = ( i ); break; } } return columns; } isSquaredMatrix( matrix ) { if( getMatrixRows( matrix ) == getMatrixColumns( matrix ) ) return true; return false; } getMatrixOrder( matrix ) { if( isSquaredMatrix( matrix ) ) return ( getMatrixRows( matrix ) ); } CreateOnes( m, n ) { ones = []; wait ( 0.05 ); for( i = 0; i < m; i ++ ) for( j = 0; j < n; j ++ ) ones[i][j] = 1; return ones; } TransposeMatrix( matrix ) { string = ""; rows = getMatrixRows( matrix ); columns = getMatrixColumns( matrix ); wait ( 0.1 ); for( u = 0; u < rows; u ++ ) { for( k = 0; k < columns; k ++ ) { string += matrix[k][u]; string += ","; } string = FixString( string ); } wait ( 0.05 ); newstring = ""; for( w = 0; w < ( string.size - 1 ); w ++ ) newstring += string[w]; return ( CreateMatrix( newstring ) ); } FixString( string ) { new = ""; for( i = 0; i < ( string.size - 1 ); i ++ ) new += string[i]; new += ";"; return new; } MultiplyMatrixes( matrix1, matrix2 ) { newm = []; sum = 0; m = getMatrixRows( matrix1 ); n = getMatrixColumns( matrix1 ); p = getMatrixRows( matrix2 ); q = getMatrixColumns( matrix2 ); if( n != p ) return; wait ( 0.1 ); for ( i = 0 ; i < m ; i ++ ) { for ( j = 0 ; j < q ; j ++ ) { for ( k = 0 ; k < p ; k++ ) sum += ( matrix1[i][k] * matrix2[k][j] ); newm[i][j] = sum; sum = 0; } } return newm; } AddMatrixes( matrix1, matrix2 ) { m = getMatrixRows( matrix1 ); n = getMatrixColumns( matrix1 ); p = getMatrixRows( matrix2 ); q = getMatrixColumns( matrix2 ); newm = []; if( m != p || n != q ) return; wait ( 0.05 ); for( i = 0; i < m; i ++ ) for( j = 0; j < n; j ++ ) newm[i][j] = ( matrix1[i][j] + matrix2[i][j] ); return newm; } Determinant( matrix ) { if( ! isSquaredMatrix( matrix ) ) return; n = getMatrixOrder( matrix ); m1 = []; m2 = []; det = 0; if( n == 1 ) return matrix[0][0]; wait ( 0.05 ); for( i = 0; i < n; i ++ ) { if( i % 2 == 0 ) { for( y = 0; y < n; y ++ ) for( x = 0; x < n; x ++ ) if(x<i) m1[x][y] = matrix[x][y+1]; else m1[x][y] = matrix[x+1][y+1]; det = det + matrix[i][0] * Determinant( m1, n - 1 ); } else { for( y = 0; y < n; y ++ ) for( x = 0; x < n; x ++ ) if(x<i) m2[x][y] = matrix[x][y+1]; else m2[x][y] = matrix[x+1][y+1]; det = det - matrix[i][0] * Determinant( m2, n - 1 ); } } return det; }

Examples of how to create a matrix and do some operations with them (I recommend to add a small wait after using each command):

Code:
matrixA = CreateMatrix( "2,3,1;1,4,0;2,2,3" ); matrixB = CreateMatrix( "1,1,2;1,1,1;2,2,1" ); detA = Determinant( matrixA ); TransA = TransposeMatrix( matrixA ); multiplication = MultiplyMatrixes( matrixA, matrixB ); add = AddMatrixes( matrixA, matrixB );

Thanks, @Yamato
Reply

#2
So much math!

Thanks, @Rendflex
Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
  [Release] nCr and Factorial Functions Yamato 2 3,749 06-18-2013, 17:24
Last Post: Nekochan
  [Release] Random Functions 1.1 Yamato 22 18,199 04-20-2013, 10:13
Last Post: Dominator56
  Matrix House 2 3,345 12-13-2012, 23:28
Last Post: House
  Functions surtek 14 14,671 09-19-2012, 07:57
Last Post: Pozzuh
Information [Solved] Info about functions, events and etc. Nerus 2 3,549 09-09-2012, 20:57
Last Post: surtek
  Seldom required functions Phl3x_ 3 4,304 06-03-2012, 10:53
Last Post: RaZ
  Help I find This functions and i need your help. Bloodfocus 5 5,106 04-23-2012, 01:43
Last Post: House
  Help Functions iPrintLnBold() [Z00MBY] Alex 7 7,861 04-16-2012, 08:44
Last Post: [Z00MBY] Alex
  [Release] Array functions master131 4 5,242 09-17-2011, 14:23
Last Post: AZUMIKKEL
  [Release] Random Functions Yamato 12 11,776 08-17-2011, 13:07
Last Post: Nekochan

Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum Powered By MyBB, Theme by © 2002-2026 Melroy van den Berg.