Tag Info

Hot answers tagged

5

I think that this kind of step-by-step assignment is probably the easiest for you to follow and apply generally at this time: aa = Table[Subscript[a, i, j], {i, 6}, {j, 6}]; bb = Table[Subscript[b, i, j], {i, 6}, {j, 6}]; cc = Table[Subscript[c, i, j], {i, 6}, {j, 6}]; new = ConstantArray[0, {12, 12}]; new[[1 ;; 3, 1 ;; 6]] = aa[[1 ;; 3]]; new[[1 ;; 3, 1 ...


4

You can use CoefficientArrays: xx = {a[0, 0], a[0, 0] + a[1, 0] + a[2, 0] + a[3, 0], a[0, 0] + a[0, 1] + a[0, 2] + a[0, 3], a[0, 0] + a[0, 1] + a[0, 2] + a[0, 3] + a[1, 0] + a[1, 1] + a[1, 2] + a[1, 3] + a[2, 0] + a[2, 1] + a[2, 2] + a[2, 3] + a[3, 0] + a[3, 1] + a[3, 2] + a[3, 3], a[1, 0], a[1, 0] + 2 a[2, 0] + 3 a[3, 0], a[1, 0] + a[1, ...


4

The suggestions bar tries to offer a useful set of follow-up operations based upon the type of a result. In the case at hand, the result is a list of lists. But it so happens that all of the sublists are the same length, which happens to be the representation of a matrix in Mathematica. So the suggestions bar has guessed that the user has a matrix in mind ...


4

Perhaps this example matrix = RandomInteger[{0, 2}, {3, 3}]; matrix // MatrixForm which displays thiis 0 0 2 1 0 2 0 0 1 Then this matrix /. v_ /; v == 0 -> "" // MatrixForm which displays this 2 1 2 1 EDIT/Append I saw you revised your question after I posted the above. Perhaps you can adapt this: StringJoin[Flatten[Table[ ...


3

In general, eigenvalues are not real. When asking for the kth largest eigenvalue, by default Mathematica sorts eigenvalues based on magnitude. When using the Arnoldi method, it is possible to specify how eigenvalues should be sorted: based on magnitude, the real part, or imaginary part. This is described under the Method option of Eigenvalues in the ...


3

One way is to start with empty matrix. Add the first column. Then loop, each time adding the next column, and checking if the rank of this matrix has increased from before, if so, keep it, else skip over to the next column. Keep doing this until you reach the last column in the original matrix, or have collected m columns, where m is the rank of the original ...


3

If RowReduce won't help, then perhaps I don't know what you're looking for. Here's my understanding of the question in which I use RowReduce to get the answer. Example A random matrix: SeedRandom[1]; mat = RandomSample[#~Join~Accumulate@RandomSample[#, 2] &@ RandomInteger[{-5, 5}, {35, 37}]]; MatrixRank[mat] (* 35 *) We can use the ...


2

per = Permutations[Range[1, 9]]; all = (Det[{{#1, #2, #3}, {#4, #5, #6}, {#7, #8, #9}}] &) @@@ per; now: maxdet = Max[all] (*412*) positions of these matrices are: pos = Flatten@Position[all, maxdet]; (*{14176, 18520, 27624, 31968, 55210, 64000, 68658, 77448, 100690, 105034, 114138, 118482, 125216, 131000, 151265, 157001, 164810, ...


2

Update 2: In Mathematica 9.0.1 this takes only 19 seconds on first evaluation and 10 seconds on subsequent evaluations. The results returned by M9 and M10 are equivalent but not given in identical form. Update: While I was writing this I tried Eigenvectors[m], which finished in 100 seconds on my machine. I'm leaving the NullSpace-based method below ...


2

As indicated by @Szabolcs, you just have to use SetAttributes[plotting, HoldAll] or even in your case SetAttributes[plotting, HoldFirst] (because you have only one argument) when defining your function. But then, there is a problem to test the header of the function argument, plotting[g_Graph] won't never plot anything because as g is now by defintion ...


2

L = StringSplit["I want to create a matrix by laying"] {"I", "want", "to", "create", "a", "matrix", "by", "laying"} Outer[f, L, L] // TableForm


2

You also need StandardDeviation to get the covariance matrix from the correlation matrix: corToCov[mat_, sd_] := Transpose[sd Transpose[sd mat]] Example: data = RandomReal[5, {10, 5}]; cormat = Correlation[data]; covmat = Covariance[data]; sd = StandardDeviation[data]; covmat == corToCov[cormat, sd] (* True *) To get the correlation matrix from a ...


2

When you export a Table, then the array cannot be arbitrarily nested. What you should do is to export your data (which is not a matrix!) in a different format. Try: Export["data.dat", m1, "Package"] Import["data.dat", "Package"][[All, 2, 1]] // MatrixForm or Export["data.dat", m1, "MX"] Import["data.dat", "MX"][[All, 2, 1]] // MatrixForm and read the ...


2

You can also use a more "mathy" approach: Assuming xx and alpha are defined as in kguler's answer, A = D[xx, {alpha}] which produces identical output. I like thinking in this way because it is useful for computing hessians (in a slightly different context).


2

Here is a modification of your code that works. The problem was that you weren't combining the Compositions for each matrix entry correctly in CircleTimes: using Plus with Composition doesn't lead to a function which can be applied subsequently to another expression. You have to make each sum of compositions into a function itself. First I'll copy the ...


2

mA = Array[a, {4, 4}] {{a[1, 1], a[1, 2], a[1, 3], a[1, 4]}, {a[2, 1], a[2, 2], a[2, 3], a[2, 4]}, {a[3, 1], a[3, 2], a[3, 3], a[3, 4]}, {a[4, 1], a[4, 2], a[4, 3], a[4, 4]}} mB = Reverse /@ (Transpose[Reverse /@ mA]) {{a[4, 4], a[3, 4], a[2, 4], a[1, 4]}, {a[4, 3], a[3, 3], a[2, 3], a[1, 3]}, {a[4, 2], a[3, 2], a[2, 2], a[1, 2]}, ...


1

Since no one gives a satisfactory answser, so I figure out a way myself which combined with Band, Diagonal and SparseArray. The Diagonal[m,k]gives the elements on the $k^{th}$ diagonal of m, illustrated as below: Band in SparseArray can repeat the values cyclically, for example: SparseArray[Band[{1, 1}, {5, 5}] -> {x, y, z}, {5, 5}] // MatrixForm ...


1

In the CUDALink user guide, there is a section describing the time out error. This can be found here about 2/3 of the way down the page under Common Errors. Essentially, under Windows, if the same GPU that is used for CUDA computation is also used for the display, the Windows Display Driver Model (WDDM) enforces a time limit on GPU computations so that the ...


1

The functions Band and SparseArray may be what you are looking for: n = {9, 9}; Normal[SparseArray[{Band[{1, 1}] -> y + 0.2, Band[{1, 3}] -> 0.2, Band[{1, 2}, n] -> {2 t1, 0}, Band[{3, 1}, n] -> {t1, 0}}, n]] // MatrixForm Just increase the dimensions in the variable n and the specified pattern(s) continue.


1

NullSpace works on both numerical and symbolic matrices. and implied by your link, under "Details" subsection, "Method" would sort of refer to the algorithm NullSpace uses. Possible settings for the Method option include "CofactorExpansion", "DivisionFreeRowReduction", and "OneStepRowReduction". The default setting of Automatic switches among these ...


1

ClearAll[rF]; rF[mat_, n_] := With[{es = Eigensystem[mat]}, With[{m = Transpose@es, o = Ordering[N@First@es, {n}]}, First@m[[o]]]] mat = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; {vals, vecs} = Eigensystem[mat] // N (* {{16.1168,-1.11684,0.},{{0.283349,0.641675,1.},{-1.28335,-0.141675, 1.},{1.,-2.,1.}}} *) rF[mat,1] $$ \left\{-\frac{3}{2} ...


1

You can get just the nth largest Eigenvalue using the syntax m = RandomReal[{-1, 1}, {5, 5}] Eigenvalues[m, {3}] Observe that this returns the third largest eigenvalue (i..e, the one with the third largest Abs[]). Eigenvectors[m, {3}] gives the corresponding eigenvector. Accordingly, you can get the smallest eigenvalues/vectors with Eigenvalues[m, ...


1

There is no single method to get the inverse of a matrix, but if you only want to know how to get the inverse for arbitrary values of the matrix, ask MMA to solve it symbolically and use the resulting expression! mat = {{a, b}, {c, d}} Inverse@mat (* {{d/(-b c + a d), -(b/(-b c + a d))}, {-(c/(-b c + a d)), a/(-b c + a d)}} *)


1

Perhaps I've missed something, but you seem to just want to append a vector (which you have already calculated) to a matrix. Documentation for Append[] shows how to do it: For your case since you already have a and b: MapThread[Append, {a, b}] // MatrixForm A different approach enables you to join matrixes to make longer rows: The following makes ...


1

the result of Eigenvalues[m]: ( using g instead of \[gamma] ) {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,g^2,0,0,0,0,0,-g,0,0,-g,0,0,0,0,0,1},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,g,0,0,0,0,0,-1,-g,0,0,0,0,0,1,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,g,0,0,0,0,-1,-g,0,0,0,0,1,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,-1,0,0,-1,0,0,1,0,0,0}, ...


1

The last value b[[5,2]] should be a 1. At least one variable must be bigger than zero. Clear["Global`*"]; c = {758, 72, 100.}; m = {{0, 500, 0}, {0, 6, 0}, {0, 0, 8}, {0, 0, 7459}, {1, 1, 1}}; b = {{6531, -1}, {2, -1}, {2, -1}, {10485, -1}, {1, 1}}; LinearProgramming[c, m, b, Automatic, Integers] (*{1,0,0}*)


1

Algohi is right, but I'm going to give a bit faster version of this. We can assume 1 is the first entry of the matrix. We can also assume that the first row and first column are in ascending order. That gives us this construction for the first row: ROWONE = {}; For[b = 2, b <= 8, b++, For[c = b + 1, c <= 9, c++, ROWONE = Append[ROWONE, {1, b, ...


1

pcF = Length /@ SparseArray[#]["AdjacencyLists"] &; pcF@reduced (* {1, 2, 1} *) Row[Grid /@ {matrix, reduced, List /@ (pcF@reduced)}, Spacer[10]] pcF2 = Length[#] == 1 & /@ SparseArray[#]["AdjacencyLists"] &; pcF2@reduced (* {True, False, True} *) Row[Grid /@ {matrix, reduced, List /@ (pcF2@reduced)}, Spacer[10]]


1

matrix = {{1, 1, 1, 1}, {0, 1, 1, 0}, {0, 0, 0, 1}};(*Same example.*) (reduced = RowReduce[matrix]) // MatrixForm r = MapIndexed[{First[#2], Count[#1, 1]} &, reduced]; r = Insert[r, {"row number", "number of 1 in row"}, 1]; Grid[r, Frame -> All] Or to make nice report, you can add tag field: r = MapIndexed[{First[#2], z = Count[#1, 1]; z, ...


1

It is not clear why you need special functions to do what you want instead of using Drop. I think you should provide a minimum working example of your starting "matrix of matrix" and what you want the end result to be. In any case try this: m = Array[FromDigits[{##}] &, {3, 3, 4}] Drop[m, {2}] // MatrixForm Drop[m, None, {2}] // MatrixForm Edit ...



Only top voted, non community-wiki answers of a minimum length are eligible