matrix

The Innards of a Rotation Function

爱⌒轻易说出口 提交于 2020-01-05 08:42:37
问题 I'm looking for information on what goes on in a rotation function that modifies a 2d matrix. I found this, but assigning the rotation to 90, 180, or 270 renders no change. Here's my code: Matrix.prototype.rotate = function(deg) { var radians = deg * Math.PI / 180, sin = Math.sin(radians), cos = Math.cos(radians), a = this.a, b = this.b, c = this.c, d = this.d, tx = this.tx, ty = this.ty; this.a = a*cos - b*sin; this.b = a*sin + b*cos; this.c = c*cos - d*sin; this.d = c*sin + d*cos; this.tx =

R - Compare 2 matrices to find rows which rows aren't in both

∥☆過路亽.° 提交于 2020-01-05 08:21:23
问题 I have two large matrices in R of differing sizes, 371 x 1502 (A) and 371 x 1207 (B). All of matrix B is included in A. A also contains many other rows mixed in. I am looking for a way to create a new matrix, C, which contains all the rows in A not found in B. I am sure there is a way to do this using data.tables and keys but I can't for the life of me figure it out. example data: a = t(matrix(c(1,2,3,4,5,6,7,8,9), nrow = 3)) b = t(matrix(c(1,2,3,7,8,9), nrow = 3)) Any help is appreciated,

how to get an incremental power matrix in matlab

北城余情 提交于 2020-01-05 07:54:12
问题 I wanted to compute the following matrix in Matlab: g=[I A . . . A^N] I used the following program in Matlab: A=[2 3;4 1]; s=A; for n=1:1:50 s(n)=A.^n; end g=[eye(1,1),s]; I am getting the following error: In an assignment A(I) = B , the number of elements in B and I must be the same. Error in s_x_calcu_v1 (line 5) s(n)=A.^n; 回答1: The problem is that you are trying to assign a matrix to a single element. In matlab calling s(n) mean you get the nth element of s , regardless of the dimensions

how to get an incremental power matrix in matlab

倾然丶 夕夏残阳落幕 提交于 2020-01-05 07:54:06
问题 I wanted to compute the following matrix in Matlab: g=[I A . . . A^N] I used the following program in Matlab: A=[2 3;4 1]; s=A; for n=1:1:50 s(n)=A.^n; end g=[eye(1,1),s]; I am getting the following error: In an assignment A(I) = B , the number of elements in B and I must be the same. Error in s_x_calcu_v1 (line 5) s(n)=A.^n; 回答1: The problem is that you are trying to assign a matrix to a single element. In matlab calling s(n) mean you get the nth element of s , regardless of the dimensions

formatting character arrays [duplicate]

不羁的心 提交于 2020-01-05 07:23:14
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Counting values by day/hour with timeseries in MATLAB This is an elementary question, but I cannot find it: I have a 3000x25 character array: 2000-01-01T00:01:01+00:00 2000-01-01T00:01:02+00:00 2000-01-01T00:01:03+00:00 2000-01-01T00:01:04+00:00 These are obviously times. I want to reformat the array to be a 3000x1 array. How can I redefine each row to be one entry in an array? (Again, this is simple, I'm sorry)

Creating diagonal matrix from array of matrices in MATLAB

做~自己de王妃 提交于 2020-01-05 07:20:11
问题 I am interested how to create a diagonal matrix from an array of matrices. I created an array of matrices in MATLAB: X<62x62x1000> it consists of 1000 matrices with dimensions 62x62 I want to create a matrix of dimensions 62000x62000 with 1000 sub matrices from array X along main diagonal. Do you have any clue how to do this, except M=blkdiag(X(:,:,1), X(:,:,2), X(:,:,3)...) because that would be to much writing. 回答1: A possible solution M = kron(speye(1000),ones(62)); M(logical(M)) = X(:);

Efficiently calculate large similarity matrix

别等时光非礼了梦想. 提交于 2020-01-05 07:12:17
问题 In a project I'm currently working reside about 200,000 users. For each of these users we defined a similarity measure with regard to an other user. This yields a similarity matrix of 200000x200000. A tad large. A naive approach (in Ruby) of calculating each entry would take days. What strategies can I employ to to make computing the matrix fields feasible? In what data store should I put this beast? 回答1: Here are some bits and pieces of an answer, there are still too many gaps in what you've

Find median of every row using matrixStats::rowMedians

£可爱£侵袭症+ 提交于 2020-01-05 07:09:09
问题 I am trying to calculate the row median for a data frame df with rowMedians from matrixStats package. Abundance Sample1 Sample2 Sample3 Sample4 Sample5 Sample6 Sample7 Species1 2 4 0 0 0 6 0 Species2 3 5 6 4 0 0 0 Species3 3 7 2 5 8 0 0 Species4 0 0 3 8 0 0 8 Species5 7 5 6 0 0 4 4 Species6 4 2 3 0 0 2 1 I want to calculate the median of every row and append them in a new column. I got an error Argument 'x' must be a vector or matrix so I tried to convert my df to a matrix. The str function

determinant of a matrix 37x37

喜夏-厌秋 提交于 2020-01-05 06:09:07
问题 I have done a program to calculate a determinant of a matrix. My program works, but the problem is that it takes long time to calculate, especially for big matrix. Could you tell me how can a perform my program in order to calculate the determinant in the shortest possible time? double Matrice::Determinant(int n) { cout<<"n = "<<n<<endl; int i,j,j1,j2; double det = 0; Matrice tmp(n,n); if (n < 1) { } else if (n == 1) { det = this->get_el(0,0); } else if (n == 2) { det = this->get_el(0,0) *

Matrix - return and pass as parameter c++

最后都变了- 提交于 2020-01-05 05:48:08
问题 I'm trying to use clear functions to do a matrix multiplication with random generated values. Therefore I'm hoping to use a function( mat_def ) to generate the matrices and another function( mat_mul ) to multiply them when the matrices are sent as parameters. #include <iostream> #include <stdio.h> #include <stdlib.h> #include <time.h> using namespace std; double mat_def(int n) //how to return the matrix { double a[n][n]; double f; for(int i=0; i<n; i++) { for(int j=0; j<n; j++) { f= rand();