matrix

Replacing Value of Diagonals in (m x m) Matrix With its Column Sum with Memory Efficient Way in C++

I have the following matrix of size m=4 0.00000 0.09130 0.09130 0.00000 0.04565 0.00000 0.00000 0.00000 0.04565 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 And I want to replace the diagonal of that matrix with (1 - sum of its column). Resulting matrix: 0.90870 0.09130 0.09130 ...

How to prepend a column to a matrix?

Ok, imagine I have this Matrix: {{1,2},{2,3}}, and I'd rather have {{4,1,2},{5,2,3}}. That is, I prepended a column to the matrix. Is there an easy way to do it? My best propsel is this: PrependColumn[vector_List, matrix_List] := Outer[Prepend[#1, #2] &, matrix, vector, 1] But it obfuscaates the code and constantly requires loading ...

How to avoid infinite recursion in C++ class templates

I have a matrix class with the size determined by template parameters. template <unsigned cRows, unsigned cCols> class Matrix { ... }; My program uses matrices of a few sizes, typically 2x2, 3x3, and 4x4. By setting the matrix size with template parameters rather than run-time parameters allows the compiler to do a lot of inlinin...

Creating planar shadows with 4x3 matrices?

Hi All, Was just wondering how I would go about creating a planar shadow from a 4x3 matrix, all online demos I've seen use 4x4 matrices instead. ...

How to read partial data from large text file in C++

I have a big text file with more then 200.000 lines, and I need to read just a few lines. For instance: line 10.000 to 20.000. Important: I don´t want to open and search the full file to extract theses lines because of performance issues. Is this possible? ...

how plot a matrix on a wxframe?

Dear all, I am starting on wx, and I need to plot a matrix (like a grid) that is stored on a list of lists on wx Frame. My matrix have to values, and I would like to set different colors for each values. mymatrix=[[100,200,200,200,100,200,200,200,100,100], [200,200,100,100,100,100,200,200,100,200], [100,10...

Finding biggest area of adjacent numbers in a matrix

This is NOT a homework. I'm a beginner in programming, and also this is my first post here - please bear with me. I was not able to find similar questions posted here. In a beginner's book, I found the following issue: # Find the biggest area of adjacent numbers in this matrix: 1 3 2 2 2 4 3 3 3 2 4 4 4 3 1 2 3 3 #--> 13 times '3' 4...

How would I do a nested sort in MATLAB?

I am looking to do a nested sort with a matrix in MATLAB. Say my matrix looks like this: [b a; b c; a c; a a] I would like to first sort by the first column and maintain that sort, then sort by the second column. The result would be: [a a; a c; b a; b c] How would it be done? ...

Sparse Multi-Dimensional Data Representation

I'm working on a cardiac simulation tool that uses 4-dimensional data, i.e. several (3-30) variables at locations in 3D space. I'm now adding some tissue geometry which will leave over 2/3 of the points in the containing 3D box outside of the tissue to be simulated, so I need a way to efficiently store the active points and not the othe...

Matrix Reporting Services Problem

I have a matrix with rows indicating a name (Ex Store name) and I have data pertaining to that in the DATA cells. I also have another date field in this format (MM/DD/YYYY). I would like to use a cross tab between Store Names and Just the Month of the date field. Jan Feb Mar Apr (From Date) A (Store Name) 10 5 ...

How can I implement matlabs ``ismember()`` command in Python?

Hello everyone, here is my problem: I would like to create a boolean matrix B that contains True everywhere that matrix A has a value contained in vector v. One inconvenient solution would be: import numpy as np >>> A = np.array([[0,1,2], [1,2,3], [2,3,4]]) array([[0, 1, 2], [1, 2, 3], [2, 3, 4]]) >>> v = [1,2] >>> B = (A...

matrix pointer and function

Hello, I want to create a program wherein I can pass a matrix to a function using pointers. I initialized and scanned 2 matrices in the void main() and then i tried to pass them to a void add function. I think i am going wrong in the syntax of declaration and calling of the function. I assigned a pointer to the base address of my ma...

Which method of matrix determinant calculation is this?

This is the approach John Carmack uses to calculate the determinant of a 4x4 matrix. From my investigations i have determined that it starts out like the laplace expansion theorem but then goes on to calculate 3x3 determinants which doesn't seem to agree with any papers i've read. // 2x2 sub-determinants float det2_01_01 = mat[0][0] *...

Matrix classes in c++

I'm doing some linear algebra math, and was looking for some really lightweight and simple to use matrix class that could handle different dimensions: 2x2, 2x1, 3x1 and 1x2 basically. I presume such class could be implemented with templates and using some specialization in some cases, for performance. Anybody know of any simple implement...

How to find a subset of a 2d array by selecting rows and columns in c?

In an (m by n) array stored as double *d (column major), what is the fastest way of selecting a range of rows and or columns: double *filter(double *mat, int m, int n, int rows[], int cols[]); invoked as: double *B; int rows[]= {1,3,5}; int cols[]={2,4}; B = filter(A, 5, 4, rows, cols); which is expected to return a 3-by-2 subset ...

error C2719: '_Val': formal parameter with __declspec(align('16')) won't be aligned?

I'm trying to create a vector for D3DXMATRIXA16 like so: vector<D3DXMATRIXA16> matrices; and am getting the error: d:\Program Files\Microsoft Visual Studio 9.0\VC\include\vector(717) : error C2719: '_Val': formal parameter with __declspec(align('16')) won't be aligned e:\projects\emuntitled\em\emscratch\emshadow.h(...

Reporting Services - Hide Matrix Column Conditionally

In a matrix report is it possible to hide a column based on value of the parent group? For example, I've got a column called "value" which I'd like to hide when the column group that contains it has a specific value. ...

Matrix multiplication - view/projection, world/projection, etc

In HLSL there's a lot of matrix multiplication and while I understand how and where to use them I'm not sure about how they are derived or what their actual goals are. So I was wondering if there was a resource online that explains this, I'm particularly curious about what is the purpose behind multiplying a world matrix by a view matri...

XNA View Matrix - Seeking explanation

I'm having some serious trouble understanding the view matrix in XNA. I've come pretty far with all the other parts and since I've just learnt myself the required maths I don't want to use the built in Matrix-functions without understanding what they do first. Now I understand the basics of rotation, projection and translation but I can...

Matrix/Vector Preference: Return copy or transform internally?

Just a quickie to get a feel for the community in general's preference: When working with objects like Vectors (mathematical, not STL) and Matrices do you prefer a library that: A) Doesn't alter the objects but returns copies instead: Vec2 Vec2::Add(float x, float y) { return Vec2(this.x + x, this.y + y); } B) Alters the objects ...