# Tag Info

1

Here is a solution that is 1000 times slower than belisarius's and is likely to scale terribly. I post it only for the purpose of illustrating that a "transparent" approach can be easily implemented in one line in Mathematica (transparent meaning that the actual steps taken are basically shown, unlike the graph-theoretic function approach, which hides some ...

10

input = {{1, 1}, {1, 2}, {1, 3}, {2, 3}, {3, 3}, {4, 4}}; ConnectedComponents@Graph[UndirectedEdge @@@ input] (* {{3, 1, 2}, {4}} *)

0

I think that you want your h to be a function of both v and x as shown in March's answer using associations. A small modification to m_golderber's answer enables this to happen. points = Table[{x, 1./(1. + .5 x)}, {x, 0, 2, .1}] Add x to the argument for h. g[x_Real,h_Symbol] := (If[0. <= 2. #[[2]] - x <= 1., h[#[[1]], x] = .5 x + .5] & /@ ...

1

The documentation for MatrixPower[] indicates that you can take the action of a matrix power on a given vector. In particular, to get a single column of a matrix power, you thus need the action of the matrix power on an appropriate unit vector. For instance, n = 6; mat = SparseArray[{{j_, k_} /; j + k == n + 1 :> 1, {k_, k_} :> 1}, {n, n}]; m = 4; ...

4

Try DeleteCases[Join[A, B], {}] or Join[A, B] /. {} -> Nothing The latter requires V10.2 or later.

1

I was going to do something similar to m_goldberg, but since he has already done that, I'll add a version that uses an Association instead of assigning DownValues, which could be a problem if there are many assignments. Our sample list: points = Transpose@{Range[0, 1, 0.1], RandomReal[{0, 1}, 11]} Then, we define the function g that assigns the ...

2

If my interpretation of your question is right (and that is quite uncertain), then the following definition of g should work for you. If my interpretation is wrong, perhaps this will help you to revise your question, so that a correct interpretation might more obvious. Note that I had to generate my own array for points since you did not provide one. ...

2

We can use the symbolic representation of the block matrix and perform the matrix operations with Inner and NonCommutativeMultiply. At the end we replace the matrix blocks with numeric or symbolic matrices. Below is an example. The package and articles at "Noncommutative Algebra Package and Systems" might be of interest if these kind of manipulations are ...

1

I have realised it is a simple answer, I can just regard $M$ as a $(4 \times 4)$ matrix, eg. \begin{eqnarray} M = \left(\begin{array}{cccc} a_{1} & a_{2} & b_{1} & b_{2} \\ a_{3} & a_{4} & b_{3} & b_{4} \\ c_{1} & c_{2} & d_{1} & d_{2} \\ c_{3} & c_{4} & d_{3} & d_{4} \end{array} \right), \end{eqnarray} now ...

2

Multidimensional matrices can be converted to Matlab's input format using the ToMatlab package: << ToMatlab` m = {{0, 0, 2 Sqrt[4 + n], 0, Sqrt[4 + n], 0, 0, 0, Sqrt[4 + n], 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 2 Sqrt[3 + n], 0, Sqrt[3 + n], 0, 0, 0, Sqrt[3 + n], 0, 0, 0, 0, 0, 0}, {2 Sqrt[4 + n], 0, 0, 0, 0, 0, Sqrt[3 + n], 0, 0, 0, Sqrt[3 + n], ...

2

A variant: f[i_, j_, n_] := n (i - 1) + j fun[n_] := f[##, n] & @@@ Subsets[Range[n], {2}] sa[n_] := Module[{r = Subsets[fun[n], {4}]}, Transpose@Partition[SparseArray[Thread[# -> 1], n^2], n] & /@ r] saproduces the desired matrices (in this case with 4 "ones" in elements below diagonal. Length[sa@#] & /@ Range[5, 10] shows the growth ...

0

First, as @Bill said, I needed to assign the TableForm of mat to mat before I had Mathematica pretty print the matrix with MatrixForm. This fixed the issue with the Inverse and ConjugateTranspose not evaluating because mat wasn't a table: (mat = Table[ n[[i]]*n[[j]] + Cos[Theta] * (KroneckerDelta[i, j] - n[[i]]*n[[j]]) + Sum[Sin[Theta] * ...

0

n = {0, 0, 1} mat = Outer[Times, n, n] + Cos[θ] (IdentityMatrix[3] - Outer[Times, n, n]) + Sin[θ] Transpose[LeviCivitaTensor[3], {1, 3, 2}].n; mat // MatrixForm

1

You defined the function as if Mathematica was using Einstein summation convention. Make the summation on $k$ explicit: n = {0, 0, 1} mat = Table[ n[[i]]*n[[j]] + Cos[Theta]*(KroneckerDelta[i, j] - n[[i]]*n[[j]]) + Sin[Theta]* Sum[LeviCivitaTensor[3][[i, k, j]]*n[[k]], {k, 1, 3}], {i, 3}, {j, 3}] // MatrixForm which gives you a rotation ...

0

As it turns out, I was getting a 3x3x3 because it was working as if I was calculating the kth index of a matrix rather than just finding the sum of an expression with index notation. Adding a sum in there with the Tensor term worked this out fine. ClearAll[dimensions, n, mat, i, j, k] dimensions = 2 n = {1, 0} mat = Table[ n[[i]]*n[[j]] + ...

4

Eh, what the heck... With RandomSample and ReplacePart: With[{ss = Subsets[Flatten@ MapIndexed[Range[#1, #2 + #1 - 1] &, Range[6, 21, 5]], {4}]}, Partition[ReplacePart[ConstantArray[0, 25], Thread[# -> 1]], 5] & /@ ss] And... MatrixForm/@%

6

indices = Flatten[Table[{i, j}, {i, 2, 5}, {j, 1, i - 1}], 1]; allarrays = SparseArray[# -> 1, 5] & /@ Subsets[indices, {4}]; The code generates 210 such matrices (see Length@allarrays). Here is a sample of one of them: allarrays[[3]] // Normal (* Out: {{0, 0, 0, 0, 0}, {1, 0, 0, 0, 0}, {1, 1, 0, 0, 0}, {0, 0, 1, 0, 0}, {0, 0, 0, 0, 0}} *) ...

7

I believe you need to specify n and convert everything to reals: "[" <> StringJoin[ Riffle[StringSplit[ExportString[N@m, "Table"], "\n"] , ";"]] <> "]" ( with n=3 ) [0. 0. 5.291502622129181 0. 2.6457513110645907 0. 0. 0. 2.6457513110645907 0. 0. 0. 0. 0. 0. 0. ; 0. 0. 0. 4.898979485566356 0. 2.449489742783178 ...

0

Transpose[Inner[D[#1, #2] &, Transpose[NN], {\[Xi]_, \[Eta]_}, List]]

0

You can use Flatten to remove the extra parentheses: Transpose[Flatten[DNN[ξ, η], 1]]; MatrixForm[%]

2

Daniel Lichtblau mentions in a comment: It's a linear system. You can use LinearSolve. Then, if you must, separate the symbolic solution into real and imaginary parts using Re and Im.

7

You need to get rid of some extraneous List wrappers A = {{1, 1, 1}, {1, -1, 2}}; B = {4, 0}; X = {x, y, z}; and then thread the two sides of your matrix equation over Equals. ContourPlot3D[Evaluate @ Thread[A.X == B], {x, -10, 10}, {y, -10, 10}, {z, -10, 10}, ContourStyle -> Opacity[.6], MeshStyle -> Gray] The graphics shown above rotate in ...

2

You are inconsistent with the number of entries in your arrays. You seem to want 5. mymatrix = Table[RandomInteger[1], {5}, {5}]; hub = {1, 1, 1, 1, 1}; auth = {0, 0, 0, 0, 0}; Table[If[mymatrix[[i, j]] == 1, auth[[i]] = auth[[i]] + hub[[j]]], {i, 5}, {j, 5}]; auth or mymatrix = Table[RandomInteger[1], {5}, {5}]; hub = {1, 1, 1, 1, 1}; auth = {0, 0, ...

1

It sounds like you want one of these: ListLinePlot[#, ImageSize -> 4*72, PlotRange -> {-5,5}]& /@ Eigenvectors[mat] or With[ {eigs = Eigenvectors[mat]}, Manipulate[ ListLinePlot[mat[[k]], ImageSize -> 4*72, PlotRange -> {-5,5}], {{k, 1}, 1, Length[eigs], 1}]] which will let you look at them one at a time. In the case of the ...

3

New version I believe this is closer to the OP's intent, although I am still having trouble parsing it completely. Here is what I think the OP wants: The recursive structure as defined in the old version of the code below. If matrix 3 is the last matrix embedded, then each copy of matrix 3 that gets embedded each has its own set of variables, but within ...

4

Edit: The matGen and matBuildAux codes are updated moving the null arrays into the module variable, offering slight readability improvements and even slighter performance improvement on very large submatrices. This is more of an extended comment than an answer because, as @march has pointed out multiple times, there is more detail required to frame your ...

3

Update: I realized that version 10 now has FindCycle, which takes care of this easily, e.g. FindCycle[PetersenGraph[5,2], 5, All]. The solution of @kglr is unfortunately flawed: to look for 6-cycles in g = GridGraph[{3, 2}], it would look at whether CycleGraph[6] is isomorphic with g, which it is not. We need to test for subgraph isomorphism without ...

1

Use forward slashes, not backslashes. That is, replace \\ with //.

0

data = {{1, 1, 0, 0, 0}, {0, 1, 0, 0, 0}, {0, 0, 1, 0, 0}, {0, 0, 1, 1, 1}, {0, 0, 1, 0, 1}, {1, 1, 0, 0, 0}, {0, 1, 1, 0, 0}}; rowHdrs = {"1", "2", "3", "4", "5", "6", "7"}; colHdrs = {"a", "b", "c", "d", "e"}; Using version 10 capabilities of Association and Dataset \$Version (* "10.2.0 for Mac OS X x86 (64-bit) (July 7, 2015)" *) dataset = ...

Top 50 recent answers are included