Questions tagged [matrix]

In mathematics, a matrix (plural matrices) is a rectangular array of numbers, symbols, or expressions, arranged in rows and columns. The individual items in a matrix are called its elements or entries.

Filter by
Sorted by
Tagged with
4
votes
2answers
5k views

Calculating n x n determinant

According to instructions and sample code from MSDN Magazine and comments from post here determinant of n x n... I changed code to be like this: ...
4
votes
3answers
170 views

Manipulating matrices for 3D drawing

I've written a short library for manipulating matrices for 3D drawing. I've tried to strike a balance between speed and readability. Anything to improve? ...
3
votes
2answers
620 views

Pair programming matrix

At work, we have a "pair programming ladder" where you can keep track of who is pairing with whom (based on check-ins). The idea is to promote "promiscuous pairing" where each developer eventually ...
2
votes
1answer
533 views

Determinant calculation of a matrix of any degree

My program calculates the determinant of a matrix of any degree. If you really can't understand my comments or indentifiers please let me know. ...
3
votes
1answer
3k views

Build a combinatorial matrix from two vectors

I want to define a matrix of values with a very simple pattern. I've achieved it with the code below but it's ugly - very difficult to read (I find) and surely not as optimal, in terms of performance, ...
1
vote
1answer
3k views

Generating adjacency matrix on random cout of graphs with output the matrix

I've developed program, which may work with graphs and its edges (connections between vertices): http://ideone.com/FDCtT0 ...
2
votes
1answer
2k views

Sparse matrix multiplication

I am working on a sparse matrix application in C and I choose compressed sparse row (CSC) and compressed sparse column (CSC) as my data structure for it. But the difficult part is I cannot improve my ...
1
vote
3answers
5k views

Searching for an element in a 2D array

For example, given a 2D array (a matrix): {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}} What are the solutions to find a number, such as 6? Here's the code I ...
6
votes
1answer
2k views

Implementing the CutHill-McKee Algorithm

I am very much interested in the Reverse Cuthil McKee Algorithm. I have seen Fortran and C or C++ implementations of it, and I decided that it would be a nice exercise to implement it in Python. I ...
5
votes
2answers
1k views

Golang solution to Project Euler #81 (min path through a matrix)

Project Euler problem 81 asks: In the 5 by 5 matrix below, ...
3
votes
2answers
451 views

addMatrix() method

Can anyone review my addMatrix() method to see if I am following the instructions correctly? These are the instructions: This is a ...
4
votes
1answer
2k views

The number of connected component

Compute the number of connected component in a matrix, saying M. Given two items with coordinates [x1, y1] and [x2, y2] in M, if M(x1, y1) == -1 and M(x2, y2) == -1 and |x1-x2| + |y1-y2| ...
2
votes
2answers
98 views

Adding matrices

This is what the code should do: Check if the first dimensions and the second dimensions of each 2-dimensionalarray are the same. If they are not the same, then return a 0x0 2-dimensional array. ...
10
votes
2answers
168 views

How to increase efficiency of matrix operation in C?

I have a N*N upper triangular matrix with property such that, all its diagonal elements are a1,a2,a3,...,aN. I want that a[i][j] (for all j>i) should be ...
2
votes
1answer
195 views

Outputting a 2^n x 2^n matrix

I've written a simple program in Python which does the following: Input: an integer \$n\$ Output: a \$2^n x 2^n\$ matrix containing small \$L\$s which fill the entire matrix except one single square....
7
votes
1answer
2k views

Using homogeneous coordinates to rotate an image

Currently, I have this code snippet, but it's a little bit slow: ...
3
votes
1answer
232 views

Getting B+ matrix (Warshall algorithm) in Matlab

Pseudocode: ...
5
votes
1answer
170 views

Processing random matrices

I am doing my research about scheduling by using Matlab. I am a new Matlab user and I have a problem with time execution of my following code: ...
4
votes
2answers
298 views

Devise an algorithm of complexity O(N) finding No of 1's from a 2 dimensional matrix[N][N] containing 1's and 0's

Assume a 2D [n][n] matrix of 1's and 0's. All the 1's in any row should come before 0's. The number of 1's in any row I should be at least the number of 1's row (i+1). Find a method and write a C ...
7
votes
1answer
510 views

Optimizing code from spectral subtraction algorithm

This is part of the code from a spectral subtraction algorithm. I'm trying to optimize it for Android. Matlab code: ...
3
votes
2answers
3k views

Templated Matrix class

I created a Matrix class. I tested it and it seems to work. Can someone tell me if this class is good? Can I improve it? Can I use more move semantics (where)? What do I have to modify? Are there ...
4
votes
1answer
364 views

Producing a matrix class that supports any size

I'm doing exercise 11.8 from Scala for impatient, asking to write a matrix class: Provide a class Matrix - you can choose whether you want to implement 2 x 2 ...
5
votes
2answers
2k views

Finding the largest product of four consecutive numbers in a grid

Project Euler #11 asks to find the largest product of four numbers of a grid, where the four numbers occur consecutive to each other vertically, horizontally, or diagonally. Here is my solution in ...
1
vote
1answer
1k views

Computing the sum of squared differences

About Data: 3D data (100x100x20). Computation/Formula and Method: I am trying to compute the sum of squared differences along rows, columns and angles for various time differences. ...
1
vote
1answer
3k views

Element-comparison NumPy matrix

I need a NumPy matrix with comparisons among all elements in a sequence: ...
3
votes
1answer
155 views

Updating a density distribution

I am running a Markov Chain Monte Carlo algorithm for updating a density distribution. There is a specific section of my code which tries to fill a very large matrix ...
5
votes
1answer
1k views

Path sum - Dijkstra's algorithm in F#

I'm learning F# and I've decided to solve Project Euler's Problem #81 with Dijkstra's algorithm. In the 5 by 5 matrix below, the minimal path sum from the top left to the bottom right, by only ...
3
votes
2answers
160 views

Attempting to eliminate var (and imperative style) from my Piece class

I've been cooking with gas since I got Daniel C Sobral's help on my last question. I am now re-reading Odersky's "Programming in Scala, 2nd Edition" (finished my first reading about this time last ...
8
votes
1answer
278 views

Computing a Discrete Cosine Transform matrix

I'm learning Haskell and I needed to work with discrete cosine transform matrices, so I made a program that generates text (usable in WolframAlpha) containing the generated matrix. The elements of ...
3
votes
2answers
4k views

Implementation of Mahalanobis distances using Eigen

I'm trying to learn C++ with Eigen. Here's my attempt at computing Mahalanobis distances of a set of points x with respect to a sub-matrix ...
4
votes
1answer
474 views

High performance exponential of a skew Hermitian matrix in Fortran 95

I'm new to Fortran, and this is pretty much my first escapade. Below is a function that I wrote which relies on calls to LAPACK. The function is sat in a module with some other functions and works ...
5
votes
2answers
8k views

Am I multiplying two matrices together correctly?

I just wanted to know if I'm doing this right. Note that all the matrices are int[16]s. ...
0
votes
1answer
472 views

Finding columns of a matrix that are the same for combinations of events

How I can change this multi-loop to reduce the computation time? A is a matrix (5 × 10000) where the fifth line contains values between 1 and 50 corresponding to ...
1
vote
1answer
289 views

Eliminating columns from a matrix where the entries in two rows are equal

Is there a way to reduce the computation time in this program that eliminates the columns of a matrix A if for a given column the element of line 4 is equal to the element in row 5: ...
0
votes
1answer
747 views

Comparing rows of a matrix with some row vectors

I have run this program for five hours and it has not yet completed. I wonder if we can make changes to reduce the computation time. I use several for loop and this greatly increases the computation ...
4
votes
1answer
463 views

Back propagation neural network

This is the first time I tried to write a back propagation ANN and I would like to know what more experienced people think of it. The code is meant to distinguish if text is written in English, French ...
4
votes
1answer
534 views

Transpose a matrix using sed

I'm trying to transpose the following data from: ...
2
votes
1answer
1k views

Fill upper triangular matrix from a list

I am looking a good way to fill up the elements of a lower triangular matrix from a list. I currently have this: ...
1
vote
4answers
2k views

STL matrix chain multiplication

Please provide positive and not-so-positive feedback on style, clarity, or any other additional feedback you would like to provide. ...
6
votes
1answer
1k views

Determine if an element exists in a sorted NxN matrix

The point of this algorithm is to see if an element exists in a NxN matrix that has its rows and columns sorted. What would you change? What did I do well? Both perspectives help so I am not left ...
1
vote
2answers
2k views

Matrix bottom left to top right

Can someone please review this simple code for printing all paths in a matrix from bottom left to top right? If an element is 1, it is a "wall" and you cannot take it. Possible steps: up and right <...
3
votes
1answer
190 views

Creating a matrix from a dyadic product

Ax, Ay, Az: [N-by-N] B=AA (dyadic product) means ...
5
votes
5answers
2k views

Finding the maximum row of a 4x4 matrix

I have written a recursive function that I believe will return the 'maximum' row of the 4x4 matrix it is fed. By 'maximum' I mean that the maximum row of the matrix. ...
4
votes
1answer
334 views

Set of linear equations

I have \$ N^2 \$ matrices. Each one is a \$ 3 \times 3 \$ matrix. I want to concatenation them to a \$ 3N \times 3N \$ matrix. I know that the big matrix is symmetric. Evaluation of whole \$ 3 \times ...
5
votes
1answer
4k views

Matrix multiplication and dot-product

Exercise 2.37. Suppose we represent vectors v = (vi) as sequences of numbers, and matrices m = (mij) as sequences of vectors (the rows of the matrix). For example, the matrix is ...
4
votes
3answers
494 views

Presidential election predictor using matrix-processing

I'm currently working on a project where I am trying to predict a presidential election based on the population density and region of a voter. I wrote a few MATLAB functions to parse the data, but it ...
4
votes
2answers
3k views

Allocating memory for a matrix with a single malloc

For an interview, I was asked to write code allocate memory for a rows*cols matrix, using a single malloc(). I want your comments about this code that I wrote: <...