matrix

Java: Cache results of computation?

I'm writing a program to calculate a value that is a measure of the similarity between two objects. The comparison is commutative, so compare(a, b) == compare(b, a). The program's output to the console is a matrix of all results. However, since the matrix has each comparison twice ((a, b) and (b, a)), I'd like to save time by only calcu...

Calculating vertices of a rotated rectangle

Hey guys, I am trying to calculate the vertices of a rotated rectangle (2D). It's easy enough if the rectangle has not been rotated, I figured that part out. If the rectangle has been rotated, I thought of two possible ways to calculate the vertices. 1) Figure out how to transform the vertices from local/object/model space (the ones I ...

Matrix Circular Shift

Does anyone know an efficient way to right circular-shift a matrix? Btw, the matrix is binary but a method to solve a non-binary matrix is also fine. Right now, I'm thinking of implementing a circular array for the rows of my matrix and updating each row whenever a shift operation is required. Another method, I was considering was impl...

Troubles: Matrices, Vectors and Arrays

As far as I understood, matrices are very inflexible to work with. Therefor, I'm trying to get an array of vectors do deal with. My needs are: to be able to add vectors and make arithmetical operations on their components. Writing the code below, require 'matrix' x = Matrix.rows( IO.readlines("input.txt").each {|line| line.split} ) p...

Limited matrices in Ruby

How come the Matrix class has no methods to edit it's vectors and components? It seems like everything inside a matrix could be read but not written. Am I mistaking? Is there some third-party elegant Matrix-like class which would allow to delete rows and intentionally edit them? Please, notice me if there are no such - I will stop searc...

[AS3] print a jpg

Hey guys, I've been trying to print a dynamically loaded jpg and for some reason it's never printing to scale, not sure what I'm doing wrong so here's what I've done so far var request:URLRequest = new URLRequest(getAbsPath("pages/" + pagePrint + "_big.jpg")); var loader:Loader = new Loader(); loader.load(request); loader.contentLoader...

Transforming a NxN binary matrix to a zero matrix using minimum row and column toggles.

Hello, This is about the question i posted regarding converting one NxN binary matrix to another . The question i asked is a code-challenge problem . However, a similar question was asked at http://stackoverflow.com/questions/1310590/matrix-conversion. I went through that thread,and have gained some idea about how to go about solving th...

read matrix from a file in C C++

Hi Just wonder, for a matrix stored in a file as what it is, i.e. each line in the file being a row of the matrix where elements are separated by space(s), how can I predetermine the size of the matrix, then create an array of the same size and read it into the array in C and C++? If you have some code example, that would be appreciated...

The right way to manage a big matrix in Java

I'm working with a big matrix (not sparse), it contains about 10^10 double. Of course I cannot keep it in memory, and I need just 1 row at time. I thought to split it in files, every file 1 row (it requires a lot of files) and just read a file every time I need a row. do you know any more efficient way? ...

Translate vector by matrix

I have a 4*4 matrix and a 3d vector. I need to translate my vector by the matrix. Not too much crazy maths notation please because i dont understand it. An example in something close to java would be fab! Thanks ...

Code challenge problem involving matrix transformation.

Hello, Im working on a code challenge problem involving transforming a given binary matrix into another. I wrote the code in C++, and it works for the test cases i looked at, but it does not pass the online judge . The problem as well as my solution is at http://bit.ly/4SEoZ . Can someone please tell me what could be going wrong ? Than...

converting a matrix of lists to a regular matrix

Take the following code: foo <- list() foo[[1]] <- list(a=1, b=2) foo[[2]] <- list(a=11, b=22) foo[[3]] <- list(a=111, b=222) result <- do.call(rbind, foo) result[,'a'] In this case, result[,'a'] shows a list. Is there a more elegant way such that result is a "regular" matrix of vectors? I imagine there are manual ways of going abou...

How can I code this problem? (C++)

I am writing a simple game which stores datasets in a 2D grid (like a chess board). Each cell in the grid may contain a single integer (0 means the cell is empty). If the cell contains a number > 0, it is said to be "filled". The set of "filled" cells on the grid is known as a "configuration". My problems is being able to "recognize" a ...

Wrong results in JavaScript table

Hi, I'm trying to create a matrix for 12-tone music. The numbers between 0-11 show the intervals between pitches. My script shows the matrix correctly as it runs initially with the page; but when we do another calculation with the button, it goes messy, even with the same pitch set. Here is my script: var exist = 0; function ex...

c++ opengl converting model coordinates to world coordinates for collision detection

Hi, (This is all in ortho mode, origin is in the top left corner, x is positive to the right, y is positive down the y axis) I have a rectangle in world space, which can have a rotation m_rotation (in degrees). I can work with the rectangle fine, it rotates, scales, everything you could want it to do. The part that I am getting reall...

How to cycle through matrix blocks?

I have some matrix which I want to cycle through blocks, the matrix could be of many different sizes, but I can know the size, is there a way to fast cycle through blocks? i.e: to fast output the indexes of the blocks, suppose a matrix of 4*4 I should have: Block1: (0,0),(0,1)(1,0)(1,1) Block2: (0,2),(0,3)(1,2)(1,3) Block3: (2,0),(2,1)(...

FLOPS Intel core and testing it with C (innerproduct)

Hey everyone, I have some misconceptions about measuring flops, on Intel architecture, is a FLOP one addition and one multiplication together? I read about this somewhere online and there is no debate that could reject this. I know that FLOP has a different meaning on different types of cpu. How do I calculate my theoretical peak FLOP...

Efficiency of perspective projection vs raytracing/ray casting

I have a very general question. I wish to determine the boundary points of a number of objects (comprising 30-50 closed polygons (z) each having around 300 points(x,y,z)). I am working with a fixed viewport which is rotated about x,y and z-axes (alpha, beta, gamma) wrt origin of coordinate system for polygons. As I see it there are two ...

Efficient Indexing method for a 2 by 2 matrix

If I fill numbers from 1 to 4 in a 2 by 2 matrix, there are 16 possible combinations. What I want to do is store values in an array of size 24 corresponding to each matrix. So given a 2 by 2 matrix, I want a efficient indexing method to index into the array directly.( I dont want comparing all 4 elements for each of 16 positions). Some...

Matrix of unknown length in MATLAB?

I'm trying to set up a zero matrix of variable length with two columns into which I can output the results of a while loop (with the intention of using it to store the step data from Euler's method with adjusted time-steps). The length will be determined by the number of iterations of the loop. I'm wondering if there's a way I can do t...