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.

543 questions
Filter by
Sorted by
Tagged with
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, ...
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 ...
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 ...
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 ...
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 ...
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, ...
446 views

Can anyone review my addMatrix() method to see if I am following the instructions correctly? These are the instructions: This is a ...
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| ...
98 views

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. ...
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 ...
194 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....
2k views

Using homogeneous coordinates to rotate an image

Currently, I have this code snippet, but it's a little bit slow: ...
231 views

Pseudocode: ...
169 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: ...
297 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 ...
508 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: ...
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 ...
359 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 ...
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 ...
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. ...
3k views

Element-comparison NumPy matrix

I need a NumPy matrix with comparisons among all elements in a sequence: ...
154 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 ...
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 ...
159 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 ...
273 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 ...
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 ...
473 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 ...
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. ...
471 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 ...
288 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: ...
746 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 ...
461 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 ...
532 views

Transpose a matrix using sed

I'm trying to transpose the following data from: ...
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: ...
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. ...
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 ...
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 <...
185 views

Creating a matrix from a dyadic product

Ax, Ay, Az: [N-by-N] B=AA (dyadic product) means ...
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. ...
333 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 ...
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 ...